here is the benchmark result for mysql driver:
k@k-ThinkPad-X270:sql$ go test -v -bench . --benchtime 60s -parallel 10
BenchmarkNoMaxLifetime-4   10000000     13480 ns/op
BenchmarkMaxLifetime1S-4   10000000     14356 ns/op
PASS
ok   _/home/k/Desktop/work/test/sql 303.967s


The benchmark code is here:
package main

import (
"database/sql"
"fmt"
"os"
"testing"
"time"

_ "github.com/go-sql-driver/mysql"
)

var db *sql.DB

func BenchmarkNoMaxLifetime(b *testing.B) {
db.SetConnMaxLifetime(0)

b.RunParallel(func(pb *testing.PB) {
var v string
for pb.Next() {
db.QueryRow("select 1").Scan(&v)
}
})
}

func BenchmarkMaxLifetime1S(b *testing.B) {
db.SetConnMaxLifetime(time.Duration(1 * time.Second))

b.RunParallel(func(pb *testing.PB) {
var v string
for pb.Next() {
db.QueryRow("select 1").Scan(&v)
}
})
}

func TestMain(m *testing.M) {
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)
}

os.Exit(m.Run())
}


-- 
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.

Reply via email to