From 7b4ac9143b947bdb59f917dcf633e1229aa801c1 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 26 Mar 2024 22:16:13 -0700 Subject: [PATCH] sqlite benchmark block location --- persist/sqlite/blocks_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/persist/sqlite/blocks_test.go b/persist/sqlite/blocks_test.go index ff150fe..e6232a2 100644 --- a/persist/sqlite/blocks_test.go +++ b/persist/sqlite/blocks_test.go @@ -84,13 +84,15 @@ func BenchmarkBlockLocation(b *testing.B) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { - c := cids[i%len(cids)] - bucket, key, err := db.BlockLocation(c) - if err != nil { - b.Fatal(err) - } else if bucket != "test" || key != c.String() { - b.Fatalf("unexpected result: %v %v", bucket, key) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + c := cids[frand.Intn(len(cids))] + bucket, key, err := db.BlockLocation(c) + if err != nil { + b.Fatal(err) + } else if bucket != "test" || key != c.String() { + b.Fatalf("unexpected result: %v %v", bucket, key) + } } - } + }) }