Go vs CGo benchmarks refactored (not TPCH)

This commit is contained in:
glebarez
2021-12-16 12:50:41 +00:00
parent 019ed373da
commit abe4fa449b
15 changed files with 1473 additions and 189 deletions

69
benchmark/util.go Normal file
View File

@@ -0,0 +1,69 @@
// Copyright 2021 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package benchmark
import (
"database/sql"
"path"
"reflect"
"runtime"
"strings"
"testing"
)
func createDB(tb testing.TB, inMemory bool, driverName string) *sql.DB {
var dsn string
if inMemory {
dsn = ":memory:"
} else {
dsn = path.Join(tb.TempDir(), "test.db")
}
db, err := sql.Open(driverName, dsn)
if err != nil {
tb.Fatal(err)
}
return db
}
func createTestTable(tb testing.TB, db *sql.DB, nRows int) {
if _, err := db.Exec("drop table if exists t"); err != nil {
tb.Fatal(err)
}
if _, err := db.Exec("create table t(i int)"); err != nil {
tb.Fatal(err)
}
if nRows > 0 {
s, err := db.Prepare("insert into t values(?)")
if err != nil {
tb.Fatal(err)
}
defer s.Close()
if _, err := db.Exec("begin"); err != nil {
tb.Fatal(err)
}
for i := 0; i < nRows; i++ {
if _, err := s.Exec(int64(i)); err != nil {
tb.Fatal(err)
}
}
if _, err := db.Exec("commit"); err != nil {
tb.Fatal(err)
}
}
}
func getFuncName(i interface{}) string {
// get function name as "package.function"
fn := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
// return last component
comps := strings.Split(fn, ".")
return comps[len(comps)-1]
}