Add Go/PostgreSQL version

This commit is contained in:
Peter J. Holzer 2021-05-07 19:34:05 +02:00 committed by Peter J. Holzer
parent 5b5d00e205
commit 8fd1912537
2 changed files with 35 additions and 0 deletions

View File

@ -33,3 +33,9 @@ rorschach:~database_connect_bench 0:14 :-) 1099% time ./dcb_perl_psql
0.00254458002746105 session 2 0.00254458002746105 session 2
./dcb_perl_psql 0.05s user 0.01s system 93% cpu 0.068 total ./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

29
dcb_go_psql.go Normal file
View File

@ -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")
}