aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-30 00:56:09 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-30 00:56:38 +0200
commit71d4c873bd12233b585637404115cfea9462c904 (patch)
treeeded14e0d5ffad139263154701eb6f115ea6b2bc /benchmark
parent24bfa86b90f7b9bec886af7e3e4f02fee25ce99c (diff)
downloadgo-oblast-71d4c873bd12233b585637404115cfea9462c904.tar.gz
add ctx arguments to most methods
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/benchmark_test.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/benchmark/benchmark_test.go b/benchmark/benchmark_test.go
index 98d5818..439ecaf 100644
--- a/benchmark/benchmark_test.go
+++ b/benchmark/benchmark_test.go
@@ -4,6 +4,7 @@
package main_test
import (
+ "context"
"crypto/sha256"
"database/sql"
"fmt"
@@ -20,6 +21,9 @@ import (
"gorm.io/gorm"
)
+// Do not use b.Context() within benchmarks, or you will merely demonstrate that using a deep stack of Context objects is expensive.
+var noctx = context.Background()
+
// This is not a real benchmark (obviously).
// Its purpose is to be the first line that is printed, while having one of the longest names,
// so that all other results are aligned with it and the table looks nice.
@@ -91,12 +95,12 @@ func BenchmarkSelectMany(b *testing.B) {
precomputedQuery := store.MustPrepareSelectQueryWhere(partialQuery)
selectWithOblast := func(b *testing.B) {
- records := must.Return(store.Select(db, query))(b)
+ records := must.Return(store.Select(noctx, db, query))(b)
assert.Equal(b, len(records), batchSize)
}
selectWithOblastWhere := func(b *testing.B) {
- records := must.Return(precomputedQuery.Select(db))(b)
+ records := must.Return(precomputedQuery.Select(noctx, db))(b)
assert.Equal(b, len(records), batchSize)
}
@@ -185,12 +189,12 @@ func BenchmarkSelectOne(b *testing.B) {
precomputedQuery := store.MustPrepareSelectQueryWhere(partialQuery)
selectWithOblast := func(b *testing.B) {
- r := must.Return(store.SelectOne(db, query))(b)
+ r := must.Return(store.SelectOne(noctx, db, query))(b)
assert.Equal(b, r.ID, recordID)
}
selectWithOblastWhere := func(b *testing.B) {
- r := must.Return(precomputedQuery.SelectOne(db))(b)
+ r := must.Return(precomputedQuery.SelectOne(noctx, db))(b)
assert.Equal(b, r.ID, recordID)
}
@@ -273,13 +277,13 @@ func BenchmarkInsertAndDelete(b *testing.B) {
records[idx] = OblastEntry{Message: "hello"}
recordsForInsert[idx] = &records[idx]
}
- must.Succeed(b, store.Insert(db, recordsForInsert...))
+ must.Succeed(b, store.Insert(noctx, db, recordsForInsert...))
for _, r := range records {
if r.ID == 0 {
b.Errorf("ID was not filled!")
}
}
- must.Succeed(b, store.Delete(db, records...))
+ must.Succeed(b, store.Delete(noctx, db, records...))
}
insertAndDeleteWithGorp := func(b *testing.B) {
@@ -429,7 +433,7 @@ func BenchmarkUpdate(b *testing.B) {
recordsForOblast[idx] = OblastEntry{Message: "hello"}
recordsForOblastForInsert[idx] = &recordsForOblast[idx]
}
- must.Succeed(b, store.Insert(db, recordsForOblastForInsert...))
+ must.Succeed(b, store.Insert(noctx, db, recordsForOblastForInsert...))
recordsForGorp := make([]any, batchSize)
for idx, r := range recordsForOblast {
recordsForGorp[idx] = new(GorpEntry(r))
@@ -444,7 +448,7 @@ func BenchmarkUpdate(b *testing.B) {
for idx := range recordsForOblast {
recordsForOblast[idx].Message = message
}
- must.Succeed(b, store.Update(db, recordsForOblast...))
+ must.Succeed(b, store.Update(noctx, db, recordsForOblast...))
}
updateWithGorp := func(b *testing.B, message string) {
for _, r := range recordsForGorp {