ethdb/memorydb: benchmark

This commit is contained in:
Martin Holst Swende 2023-11-07 10:13:20 +01:00
parent 1395f05244
commit 8ae3c6fc58
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -19,6 +19,7 @@ package memorydb
import (
"testing"
"encoding/binary"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/dbtest"
)
@ -30,3 +31,20 @@ func TestMemoryDB(t *testing.T) {
})
})
}
// BenchmarkBatchAllocs measures the time/allocs for storing 120 kB of data
func BenchmarkBatchAllocs(b *testing.B) {
b.ReportAllocs()
var key = make([]byte, 20)
var val = make([]byte, 100)
// 120 * 1_000 -> 120_000 == 120kB
for i := 0; i < b.N; i++ {
batch := New().NewBatch()
for j := uint64(0); j < 1000; j++ {
binary.BigEndian.PutUint64(key, j)
binary.BigEndian.PutUint64(val, j)
batch.Put(key, val)
}
batch.Write()
}
}