Benchmark is not fair to this problem, it is the mean latency value. This time I wrote a simple test, and just log the time elapsed.
Here is the code: package main import ( "database/sql" "fmt" "os" "time" _ "github.com/go-sql-driver/mysql" ) var db *sql.DB func RunNoMaxLifetime() { db.SetConnMaxLifetime(0) var v string for i := 0; i < 10; i++ { tBegin := time.Now() db.QueryRow("select 1").Scan(&v) fmt.Printf("max_lifetime=0, elapsed=%v\n", time.Since(tBegin)) time.Sleep(time.Second) } } func RunMaxLifetime1S() { db.SetConnMaxLifetime(time.Duration(1 * time.Second)) var v string for i := 0; i < 10; i++ { tBegin := time.Now() db.QueryRow("select 1").Scan(&v) fmt.Printf("max_lifetime=1s, elapsed=%v\n", time.Since(tBegin)) time.Sleep(time.Second) } } func main() { var err error if db, err = sql.Open("mysql", "test:test@tcp(127.0.0.1:3306)/test"); err != nil { fmt.Fprintf(os.Stderr, "sql.Open(): %v", err) os.Exit(1) } RunNoMaxLifetime() RunMaxLifetime1S() } here is the output: max_lifetime=0, elapsed=328.687µs max_lifetime=0, elapsed=336.997µs max_lifetime=0, elapsed=224.982µs max_lifetime=0, elapsed=343.504µs max_lifetime=0, elapsed=447.579µs max_lifetime=0, elapsed=330.273µs max_lifetime=0, elapsed=332.782µs max_lifetime=0, elapsed=277.991µs max_lifetime=0, elapsed=391.225µs max_lifetime=0, elapsed=373.826µs max_lifetime=1s, elapsed=1.438923ms max_lifetime=1s, elapsed=1.553653ms max_lifetime=1s, elapsed=1.497325ms max_lifetime=1s, elapsed=1.572134ms max_lifetime=1s, elapsed=1.582973ms max_lifetime=1s, elapsed=1.393672ms max_lifetime=1s, elapsed=1.321443ms max_lifetime=1s, elapsed=1.090508ms max_lifetime=1s, elapsed=875.897µs max_lifetime=1s, elapsed=1.685481ms -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.