MCPcopy
hub / github.com/jackc/pgx / benchmarkWriteNRowsViaInsert

Function benchmarkWriteNRowsViaInsert

bench_test.go:404–434  ·  view source on GitHub ↗
(b *testing.B, n int)

Source from the content-addressed store, hash-verified

402}
403
404func benchmarkWriteNRowsViaInsert(b *testing.B, n int) {
405 conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
406 defer closeConn(b, conn)
407
408 mustExec(b, conn, benchmarkWriteTableCreateSQL)
409 _, err := conn.Prepare(context.Background(), "insert_t", benchmarkWriteTableInsertSQL)
410 if err != nil {
411 b.Fatal(err)
412 }
413
414 for b.Loop() {
415 src := newBenchmarkWriteTableCopyFromSrc(n)
416
417 tx, err := conn.Begin(context.Background())
418 if err != nil {
419 b.Fatal(err)
420 }
421
422 for src.Next() {
423 values, _ := src.Values()
424 if _, err = tx.Exec(context.Background(), "insert_t", values...); err != nil {
425 b.Fatalf("Exec unexpectedly failed with: %v", err)
426 }
427 }
428
429 err = tx.Commit(context.Background())
430 if err != nil {
431 b.Fatal(err)
432 }
433 }
434}
435
436func benchmarkWriteNRowsViaBatchInsert(b *testing.B, n int) {
437 conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))

Calls 11

mustExecFunction · 0.85
mustConnectFunction · 0.70
mustParseConfigFunction · 0.70
closeConnFunction · 0.70
PrepareMethod · 0.65
BeginMethod · 0.65
NextMethod · 0.65
ValuesMethod · 0.65
ExecMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected