-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbulkprep_bench_test.go
More file actions
49 lines (44 loc) · 1.3 KB
/
Copy pathbulkprep_bench_test.go
File metadata and controls
49 lines (44 loc) · 1.3 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
package sqlpro
import "testing"
// benchInsertRow mirrors the finding's shape: 6 simple fields
// (bulk insert during fylr indexing).
type benchInsertRow struct {
ID int64 `db:"id,pk,omitempty"`
Name string `db:"name"`
Kind string `db:"kind"`
Num int64 `db:"num"`
Val float64 `db:"val"`
Note string `db:"note,omitempty"`
}
func makeBenchInsertRows(n int) []*benchInsertRow {
rows := make([]*benchInsertRow, 0, n)
for i := 0; i < n; i++ {
rows = append(rows, &benchInsertRow{
Name: "name-a", Kind: "kind-b", Num: int64(i), Val: float64(i) * 1.5,
})
}
return rows
}
// BenchmarkBulkRowPrep measures the Go-side row preparation done by
// insertBulkContext: valuesFromStruct per row plus escValueForInsert per
// emitted value. This is exactly the path where isZero runs twice per field.
func BenchmarkBulkRowPrep(b *testing.B) {
const n = 1000
rows := makeBenchInsertRows(n)
db2 := dbConn.(*db)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, r := range rows {
values, info, err := db2.valuesFromStruct(*r)
if err != nil {
b.Fatal(err)
}
for key, value := range values {
_ = db2.escValueForInsert(value, info[key])
}
}
}
}
// BenchmarkInsertBulkSQLite measures the full InsertBulk path (prep + exec)
// through the real SQLite connection from TestMain.