mirror of
https://github.com/safing/portmaster
synced 2025-09-16 01:39:41 +00:00
Add option to use prepared statements for SQLite PutMany
This commit is contained in:
parent
2c8ab54104
commit
9b12dfffc2
3 changed files with 216 additions and 0 deletions
86
base/database/storage/sqlite/prepared_test.go
Normal file
86
base/database/storage/sqlite/prepared_test.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package sqlite
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkPutMany(b *testing.B) {
|
||||
// Configure prepared statement usage.
|
||||
origSetting := UsePreparedStatements
|
||||
UsePreparedStatements = false
|
||||
defer func() {
|
||||
UsePreparedStatements = origSetting
|
||||
}()
|
||||
|
||||
// Run benchmark.
|
||||
benchPutMany(b)
|
||||
}
|
||||
|
||||
func BenchmarkPutManyPreparedStmt(b *testing.B) {
|
||||
// Configure prepared statement usage.
|
||||
origSetting := UsePreparedStatements
|
||||
UsePreparedStatements = true
|
||||
defer func() {
|
||||
UsePreparedStatements = origSetting
|
||||
}()
|
||||
|
||||
// Run benchmark.
|
||||
benchPutMany(b)
|
||||
}
|
||||
|
||||
func benchPutMany(b *testing.B) { //nolint:thelper
|
||||
// Start database.
|
||||
testDir := b.TempDir()
|
||||
db, err := openSQLite("test", testDir, false)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
// shutdown
|
||||
err = db.Shutdown()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Start benchmarking.
|
||||
b.ResetTimer()
|
||||
|
||||
// Benchmark PutMany.
|
||||
records, errs := db.PutMany(false)
|
||||
for i := range b.N {
|
||||
// Create test record.
|
||||
newTestRecord := &TestRecord{
|
||||
S: "banana",
|
||||
I: 42,
|
||||
I8: 42,
|
||||
I16: 42,
|
||||
I32: 42,
|
||||
I64: 42,
|
||||
UI: 42,
|
||||
UI8: 42,
|
||||
UI16: 42,
|
||||
UI32: 42,
|
||||
UI64: 42,
|
||||
F32: 42.42,
|
||||
F64: 42.42,
|
||||
B: true,
|
||||
}
|
||||
newTestRecord.UpdateMeta()
|
||||
newTestRecord.SetKey("test:" + strconv.Itoa(i))
|
||||
|
||||
select {
|
||||
case records <- newTestRecord:
|
||||
case err := <-errs:
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Finalize.
|
||||
close(records)
|
||||
err = <-errs
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue