-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer_bench_test.go
More file actions
68 lines (63 loc) · 1.47 KB
/
Copy pathpointer_bench_test.go
File metadata and controls
68 lines (63 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package sqlite
import (
"context"
"database/sql"
"errors"
"testing"
)
// benchSetup opens an in-memory DB pinned to 1 conn, registers a noop
// UDF, and returns a pinned *sql.Conn ready for prepared-statement
// benchmarks.
func benchSetup(b *testing.B) (*sql.DB, *sql.Conn) {
b.Helper()
db, err := sql.Open(DriverNameSQLite3, ":memory:")
if err != nil {
b.Fatal(err)
}
db.SetMaxOpenConns(1)
b.Cleanup(func() { _ = db.Close() })
sc, err := db.Conn(context.Background())
if err != nil {
b.Fatal(err)
}
b.Cleanup(func() { _ = sc.Close() })
if err := sc.Raw(func(driverConn any) error {
c, ok := driverConn.(*Conn)
if !ok {
return errors.New("not *Conn")
}
return c.RegisterFunc("noop", func(any) int64 { return 0 }, false)
}); err != nil {
b.Fatal(err)
}
return db, sc
}
func BenchmarkPointer_BindRelease(b *testing.B) {
_, sc := benchSetup(b)
ctx := context.Background()
stmt, err := sc.PrepareContext(ctx, `SELECT noop(?)`)
if err != nil {
b.Fatal(err)
}
defer stmt.Close()
slice := []int{1, 2, 3}
b.ReportAllocs()
b.ResetTimer()
for range b.N {
if _, err := stmt.ExecContext(ctx, Pointer(slice)); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkPointer_Registry_StoreLoad(b *testing.B) {
// Direct registry exercise (no SQLite round-trip) — measures the
// mutex-guarded path in isolation.
v := []int{10, 20, 30}
b.ReportAllocs()
b.ResetTimer()
for range b.N {
tok := storePointer(v)
_, _ = loadPointer(tok)
releasePointer(tok)
}
}