github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/store/cachekv/store_bench_test.go (about) 1 package cachekv_test 2 3 import ( 4 "crypto/rand" 5 "sort" 6 "testing" 7 8 dbm "github.com/fibonacci-chain/fbc/libs/tm-db" 9 10 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/cachekv" 11 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/dbadapter" 12 ) 13 14 func benchmarkCacheKVStoreIterator(numKVs int, b *testing.B) { 15 mem := dbadapter.Store{DB: dbm.NewMemDB()} 16 cstore := cachekv.NewStore(mem) 17 keys := make([]string, numKVs) 18 19 for i := 0; i < numKVs; i++ { 20 key := make([]byte, 32) 21 value := make([]byte, 32) 22 23 _, _ = rand.Read(key) 24 _, _ = rand.Read(value) 25 26 keys[i] = string(key) 27 cstore.Set(key, value) 28 } 29 30 sort.Strings(keys) 31 32 for n := 0; n < b.N; n++ { 33 iter := cstore.Iterator([]byte(keys[0]), []byte(keys[numKVs-1])) 34 35 for _ = iter.Key(); iter.Valid(); iter.Next() { 36 } 37 38 iter.Close() 39 } 40 } 41 42 func BenchmarkCacheKVStoreIterator500(b *testing.B) { benchmarkCacheKVStoreIterator(500, b) } 43 func BenchmarkCacheKVStoreIterator1000(b *testing.B) { benchmarkCacheKVStoreIterator(1000, b) } 44 func BenchmarkCacheKVStoreIterator10000(b *testing.B) { benchmarkCacheKVStoreIterator(10000, b) } 45 func BenchmarkCacheKVStoreIterator50000(b *testing.B) { benchmarkCacheKVStoreIterator(50000, b) } 46 func BenchmarkCacheKVStoreIterator100000(b *testing.B) { benchmarkCacheKVStoreIterator(100000, b) }