cosmos-sdk/store/cache/benchmark_test.go
Likhita Polavarapu 7559d9ecd3
refactor: create go.mod for store (#14746)
Co-authored-by: Marko <marbar3778@yahoo.com>
2023-01-25 13:31:56 +00:00

50 lines
955 B
Go

package cache
import (
"testing"
"cosmossdk.io/store/types"
)
func freshMgr() *CommitKVStoreCacheManager {
return &CommitKVStoreCacheManager{
caches: map[string]types.CommitKVStore{
"a1": nil,
"alalalalalal": nil,
},
}
}
func populate(mgr *CommitKVStoreCacheManager) {
mgr.caches["this one"] = (types.CommitKVStore)(nil)
mgr.caches["those ones are the ones"] = (types.CommitKVStore)(nil)
mgr.caches["very huge key right here and there are we going to ones are the ones"] = (types.CommitKVStore)(nil)
}
func BenchmarkReset(b *testing.B) {
b.ReportAllocs()
mgr := freshMgr()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
mgr.Reset()
if len(mgr.caches) != 0 {
b.Fatal("Reset failed")
}
populate(mgr)
if len(mgr.caches) == 0 {
b.Fatal("populate failed")
}
mgr.Reset()
if len(mgr.caches) != 0 {
b.Fatal("Reset failed")
}
}
if mgr == nil {
b.Fatal("Impossible condition")
}
}