github.com/Finschia/finschia-sdk@v0.48.1/store/cache/benchmark_test.go (about) 1 package cache 2 3 import ( 4 "testing" 5 6 "github.com/Finschia/finschia-sdk/store/types" 7 ) 8 9 func freshMgr() *CommitKVStoreCacheManager { 10 return &CommitKVStoreCacheManager{ 11 caches: map[string]types.CommitKVStore{ 12 "a1": nil, 13 "alalalalalal": nil, 14 }, 15 } 16 } 17 18 func populate(mgr *CommitKVStoreCacheManager) { 19 mgr.caches["this one"] = (types.CommitKVStore)(nil) 20 mgr.caches["those ones are the ones"] = (types.CommitKVStore)(nil) 21 mgr.caches["very huge key right here and there are we going to ones are the ones"] = (types.CommitKVStore)(nil) 22 } 23 24 func BenchmarkReset(b *testing.B) { 25 b.ReportAllocs() 26 mgr := freshMgr() 27 28 b.ResetTimer() 29 b.ReportAllocs() 30 31 for i := 0; i < b.N; i++ { 32 mgr.Reset() 33 if len(mgr.caches) != 0 { 34 b.Fatal("Reset failed") 35 } 36 populate(mgr) 37 if len(mgr.caches) == 0 { 38 b.Fatal("populate failed") 39 } 40 mgr.Reset() 41 if len(mgr.caches) != 0 { 42 b.Fatal("Reset failed") 43 } 44 } 45 46 if mgr == nil { 47 b.Fatal("Impossible condition") 48 } 49 }