Skip to content

Commit

Permalink
Fix secondary index benchmark
Browse files Browse the repository at this point in the history
BenchmarkDB_WriteTxn_100_SecondaryIndex was reconstructing the tags set
on every insert which cost a bit of time and wasn't relevant for the benchmark.

While at it simplify the batch benchmarks to not have two loops.

Signed-off-by: Jussi Maki <[email protected]>
  • Loading branch information
joamaki committed Aug 20, 2024
1 parent c30b8ae commit 3a554b8
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,51 +53,42 @@ func benchmarkDB_WriteTxn_batch(b *testing.B, batchSize int) {
db, table := newTestDBWithMetrics(b, &NopMetrics{})
n := b.N
b.ResetTimer()

for n > 0 {
txn := db.WriteTxn(table)
for j := 0; j < batchSize; j++ {
_, _, err := table.Insert(txn, testObject{ID: uint64(j)})
toWrite := min(n, batchSize)
for i := range toWrite {
_, _, err := table.Insert(txn, testObject{ID: uint64(i)})
if err != nil {
b.Fatalf("Insert error: %s", err)
}
}
txn.Commit()
n -= batchSize
n -= toWrite
}
txn := db.WriteTxn(table)
for j := 0; j < n; j++ {
_, _, err := table.Insert(txn, testObject{ID: uint64(j)})
if err != nil {
b.Fatalf("Insert error: %s", err)
}
}
txn.Commit()

b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "objects/sec")
}

func BenchmarkDB_WriteTxn_100_SecondaryIndex(b *testing.B) {
db, table := newTestDBWithMetrics(b, &NopMetrics{}, tagsIndex)
batchSize := 100
n := b.N
tags := []string{"test"}
tagSet := part.NewSet("test")

for n > 0 {
txn := db.WriteTxn(table)
for j := 0; j < 100; j++ {
_, _, err := table.Insert(txn, testObject{ID: uint64(j), Tags: part.NewSet(tags...)})
toWrite := min(n, batchSize)
for i := range toWrite {
_, _, err := table.Insert(txn, testObject{ID: uint64(i), Tags: tagSet})
if err != nil {
b.Fatalf("Insert error: %s", err)
}
}
txn.Commit()
n -= 100
}
txn := db.WriteTxn(table)
for j := 0; j < n; j++ {
_, _, err := table.Insert(txn, testObject{ID: uint64(j), Tags: part.NewSet(tags...)})
if err != nil {
b.Fatalf("Insert error: %s", err)
}
n -= toWrite
}
txn.Commit()

b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "objects/sec")
}

Expand Down

0 comments on commit 3a554b8

Please sign in to comment.