all: ensure b.ReportAllocs() in all the benchmarks (#8460)

With this change, we'll get details on the number of
allocations performed by code. Later on when we have
continuous benchmarking infrastructure, this change
will prove useful to flag regressions.

Fixes #8459

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
Emmanuel T Odeke
2021-01-27 23:52:08 -08:00
committed by GitHub
co-authored by Alessio Treglia
parent 580e9681a5
commit 784a9a69a1
15 changed files with 25 additions and 0 deletions
+1
View File
@@ -22,6 +22,7 @@ func populate(mgr *CommitKVStoreCacheManager) {
}
func BenchmarkReset(b *testing.B) {
b.ReportAllocs()
mgr := freshMgr()
b.ResetTimer()
+1
View File
@@ -12,6 +12,7 @@ import (
)
func benchmarkCacheKVStoreIterator(numKVs int, b *testing.B) {
b.ReportAllocs()
mem := dbadapter.Store{DB: dbm.NewMemDB()}
cstore := cachekv.NewStore(mem)
keys := make([]string, numKVs)
+2
View File
@@ -516,6 +516,7 @@ func (krc *keyRangeCounter) key() int {
func bz(s string) []byte { return []byte(s) }
func BenchmarkCacheKVStoreGetNoKeyFound(b *testing.B) {
b.ReportAllocs()
st := newCacheKVStore()
b.ResetTimer()
// assumes b.N < 2**24
@@ -525,6 +526,7 @@ func BenchmarkCacheKVStoreGetNoKeyFound(b *testing.B) {
}
func BenchmarkCacheKVStoreGetKeyFound(b *testing.B) {
b.ReportAllocs()
st := newCacheKVStore()
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
+1
View File
@@ -556,6 +556,7 @@ func TestIAVLStoreQuery(t *testing.T) {
}
func BenchmarkIAVLIteratorNext(b *testing.B) {
b.ReportAllocs()
db := dbm.NewMemDB()
treeSize := 1000
tree, err := iavl.NewMutableTree(db, cacheSize)
+2
View File
@@ -689,6 +689,7 @@ func BenchmarkMultistoreSnapshotRestore1M(b *testing.B) {
}
func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) {
b.ReportAllocs()
b.StopTimer()
source := newMultiStoreWithGeneratedData(dbm.NewMemDB(), stores, storeKeys)
version := source.LastCommitID().Version
@@ -716,6 +717,7 @@ func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) {
}
func benchmarkMultistoreSnapshotRestore(b *testing.B, stores uint8, storeKeys uint64) {
b.ReportAllocs()
b.StopTimer()
source := newMultiStoreWithGeneratedData(dbm.NewMemDB(), stores, storeKeys)
version := uint64(source.LastCommitID().Version)