//go:build cgo && sqlite_fts5 package bench import ( "context" "database/sql" "path/filepath" "testing" _ "github.com/mattn/go-sqlite3" ) func openMattn(b *testing.B) *sql.DB { b.Helper() tmpDir := b.TempDir() dsn := filepath.Join(tmpDir, "bench.db") db, err := sql.Open("sqlite3", dsn+"?_journal_mode=WAL&_synchronous=NORMAL") if err != nil { b.Fatal(err) } db.SetMaxOpenConns(1) if _, err := db.ExecContext(context.Background(), schema); err != nil { b.Fatal(err) } b.Cleanup(func() { _ = db.Close() }) return db } func BenchmarkInsert_Mattn(b *testing.B) { rows := loadChunks(b, dataPath) b.ResetTimer() for i := 0; i < b.N; i++ { db := openMattn(b) if err := insertAll(context.Background(), db, rows); err != nil { b.Fatal(err) } } } func BenchmarkQuery_Mattn(b *testing.B) { db := openMattn(b) rows := loadChunks(b, dataPath) if err := insertAll(context.Background(), db, rows); err != nil { b.Fatal(err) } ctx := context.Background() b.ResetTimer() for i := 0; i < b.N; i++ { for _, q := range queries { if _, _, err := runQuery(ctx, db, q); err != nil { b.Fatal(err) } } } } func BenchmarkRoundTrip_Mattn(b *testing.B) { rows := loadChunks(b, dataPath) ctx := context.Background() b.ResetTimer() for i := 0; i < b.N; i++ { db := openMattn(b) if err := insertAll(ctx, db, rows); err != nil { b.Fatal(err) } for _, q := range queries { if _, _, err := runQuery(ctx, db, q); err != nil { b.Fatal(err) } } } }