diff options
| author | Jonathan Amsterdam <jba@google.com> | 2020-11-23 13:10:44 -0500 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2020-11-24 12:29:45 +0000 |
| commit | 8dd5fd7ca7087ed98c82ef77fb74ddc499267e2b (patch) | |
| tree | 70170404ed5e9dea19e6516d0aa4271baa94809b /internal/database/database_test.go | |
| parent | 7a3ca68e1261a3dc43b55af6def2286fb3c73326 (diff) | |
| download | go-x-pkgsite-8dd5fd7ca7087ed98c82ef77fb74ddc499267e2b.tar.xz | |
internal/database: benchmark pgx copy against bulk insert
Add a benchmark which demonstrates that pgx's CopyFrom method
is significantly faster than doing a bulk insert with pq. In this
simple example, it is 55 times faster (!).
For golang/go#42707
Change-Id: I8bb37ba95b6207ead320b9720fbcc5a2fb8c8514
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/272506
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/database/database_test.go')
| -rw-r--r-- | internal/database/database_test.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/internal/database/database_test.go b/internal/database/database_test.go index 93ff1bfc..f4d949e8 100644 --- a/internal/database/database_test.go +++ b/internal/database/database_test.go @@ -23,12 +23,13 @@ import ( const testTimeout = 5 * time.Second +const testDBName = "discovery_postgres_test" + var testDB *DB func TestMain(m *testing.M) { - const dbName = "discovery_postgres_test" - if err := dbtest.CreateDBIfNotExists(dbName); err != nil { + if err := dbtest.CreateDBIfNotExists(testDBName); err != nil { if errors.Is(err, derrors.NotFound) && os.Getenv("GO_DISCOVERY_TESTDB") != "true" { log.Printf("SKIPPING: could not connect to DB (see doc/postgres.md to set up): %v", err) return @@ -36,7 +37,7 @@ func TestMain(m *testing.M) { log.Fatal(err) } var err error - testDB, err = Open("postgres", dbtest.DBConnURI(dbName), "test") + testDB, err = Open("postgres", dbtest.DBConnURI(testDBName), "test") if err != nil { log.Fatalf("Open: %v %[1]T", err) } |
