From 8fd1912537996bfaae5bc235267be4d7e3345011 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 7 May 2021 19:34:05 +0200 Subject: [PATCH] Add Go/PostgreSQL version --- Results | 6 ++++++ dcb_go_psql.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 dcb_go_psql.go diff --git a/Results b/Results index 99f3d8a..b935632 100644 --- a/Results +++ b/Results @@ -33,3 +33,9 @@ rorschach:~database_connect_bench 0:14 :-) 1099% time ./dcb_perl_psql 0.00254458002746105 session 2 ./dcb_perl_psql 0.05s user 0.01s system 93% cpu 0.068 total +trintignant:~/wrk/database_connect_bench 19:29 :-) 1077% time ./dcb_go_psql +2021-05-07 19:32:40.307679 +0200 CEST +0.017314667 connect +0.0178164 session +./dcb_go_psql 0.01s user 0.01s system 52% cpu 0.044 total + diff --git a/dcb_go_psql.go b/dcb_go_psql.go new file mode 100644 index 0000000..27ca26c --- /dev/null +++ b/dcb_go_psql.go @@ -0,0 +1,29 @@ +package main + +import ( + "time" + "fmt" + "log" + "database/sql" + + _ "github.com/lib/pq" +) + +func main() { + t0 := time.Now() + db, err := sql.Open("postgres", "host=/run/postgresql") + if err != nil { + log.Fatal(err) + } + + tx, _ := db.Begin() + d1 := time.Since(t0) + row := tx.QueryRow("select current_timestamp") + var db_ts time.Time + row.Scan(&db_ts) + fmt.Println(db_ts) + db.Close() + d2 := time.Since(t0) + fmt.Println(d1.Seconds(), "connect") + fmt.Println(d2.Seconds(), "session") +}