diff options
Diffstat (limited to 'freelist_test.go')
-rw-r--r-- | freelist_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/freelist_test.go b/freelist_test.go index 792ca92..8caeab2 100644 --- a/freelist_test.go +++ b/freelist_test.go @@ -1,7 +1,9 @@ package bolt import ( + "math/rand" "reflect" + "sort" "testing" "unsafe" ) @@ -127,3 +129,28 @@ func TestFreelist_write(t *testing.T) { t.Fatalf("exp=%v; got=%v", exp, f2.ids) } } + +func Benchmark_FreelistRelease10K(b *testing.B) { benchmark_FreelistRelease(b, 10000) } +func Benchmark_FreelistRelease100K(b *testing.B) { benchmark_FreelistRelease(b, 100000) } +func Benchmark_FreelistRelease1000K(b *testing.B) { benchmark_FreelistRelease(b, 1000000) } +func Benchmark_FreelistRelease10000K(b *testing.B) { benchmark_FreelistRelease(b, 10000000) } + +func benchmark_FreelistRelease(b *testing.B, size int) { + ids := randomPgids(size) + pending := randomPgids(len(ids) / 400) + b.ResetTimer() + for i := 0; i < b.N; i++ { + f := &freelist{ids: ids, pending: map[txid][]pgid{1: pending}} + f.release(1) + } +} + +func randomPgids(n int) []pgid { + rand.Seed(42) + pgids := make(pgids, n) + for i := range pgids { + pgids[i] = pgid(rand.Int63()) + } + sort.Sort(pgids) + return pgids +} |