mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-28 18:01:48 +08:00
BenchmarkReading1: use testing.TB.TempDir()
This commit is contained in:
17
cgo_test.go
17
cgo_test.go
@@ -8,8 +8,8 @@ package sqlite // import "modernc.org/sqlite"
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
@@ -17,17 +17,6 @@ import (
|
||||
|
||||
const gcoDriver = "sqlite3"
|
||||
|
||||
func prepareDatabase() string {
|
||||
//if this fails you should probably clean your folders
|
||||
for i := 0; ; i++ {
|
||||
path := fmt.Sprintf("%dbench.db", i)
|
||||
_, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
return path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var drivers = []string{
|
||||
driverName,
|
||||
gcoDriver,
|
||||
@@ -49,6 +38,7 @@ func makename(inMemory bool, driver string) string {
|
||||
}
|
||||
|
||||
func reading1Memory(b *testing.B, drivername, file string) {
|
||||
os.Remove(file)
|
||||
db, err := sql.Open(drivername, file)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
@@ -105,10 +95,11 @@ func reading1Memory(b *testing.B, drivername, file string) {
|
||||
}
|
||||
|
||||
func BenchmarkReading1(b *testing.B) {
|
||||
dir := b.TempDir()
|
||||
for _, memory := range inMemory {
|
||||
filename := "file::memory:"
|
||||
if !memory {
|
||||
filename = prepareDatabase()
|
||||
filename = filepath.Join(dir, "test.db")
|
||||
}
|
||||
for _, driver := range drivers {
|
||||
b.Run(makename(memory, driver), func(b *testing.B) {
|
||||
|
||||
Reference in New Issue
Block a user