From 0c1240360dbf7ff04423ff3d2dfcabf7600a290e Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 22 Oct 2022 23:37:31 +0200 Subject: [PATCH] index: add garbage collection benchmark Allocates an index and repeatedly triggers the GC. --- internal/index/master_index_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/index/master_index_test.go b/internal/index/master_index_test.go index 9a1970827..5d12956bd 100644 --- a/internal/index/master_index_test.go +++ b/internal/index/master_index_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/rand" + "runtime" "testing" "time" @@ -323,6 +324,17 @@ func BenchmarkMasterIndexEach(b *testing.B) { } } +func BenchmarkMasterIndexGC(b *testing.B) { + mIdx, _ := createRandomMasterIndex(b, rand.New(rand.NewSource(0)), 100, 10000) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + runtime.GC() + } + runtime.KeepAlive(mIdx) +} + var ( snapshotTime = time.Unix(1470492820, 207401672) depth = 3