mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-05 07:46:50 +08:00
Go vs CGo benchmarks refactored (not TPCH)
This commit is contained in:
45
benchmark/bench_test.go
Normal file
45
benchmark/bench_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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.
|
||||
|
||||
// this file allows to run benchmarks via go test
|
||||
package benchmark
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkSelect(b *testing.B) {
|
||||
doBenchmarkOfNrows(b, benchmarkSelect)
|
||||
}
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/-/issues/39
|
||||
func BenchmarkInsert(b *testing.B) {
|
||||
doBenchmarkOfNrows(b, benchmarkInsert)
|
||||
}
|
||||
|
||||
func doBenchmarkOfNrows(b *testing.B, benchFunc bechmarkOfNRows) {
|
||||
for _, isMemoryDB := range inMemory { // in-memory: on/off
|
||||
for _, e := range rowCountsE { // number of rows in table
|
||||
for _, driverName := range drivers { // drivers
|
||||
|
||||
// create new DB
|
||||
db := createDB(b, isMemoryDB, driverName)
|
||||
|
||||
// run benchmark
|
||||
b.Run(
|
||||
makeName(isMemoryDB, driverName, e),
|
||||
func(b *testing.B) {
|
||||
benchFunc(b, db, int(math.Pow10(e)))
|
||||
},
|
||||
)
|
||||
|
||||
// close DB
|
||||
if err := db.Close(); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user