From 8ae3c6fc5836bd871d1aa590fb37b31dc69272fd Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 7 Nov 2023 10:13:20 +0100 Subject: [PATCH] ethdb/memorydb: benchmark --- ethdb/memorydb/memorydb_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ethdb/memorydb/memorydb_test.go b/ethdb/memorydb/memorydb_test.go index dba18ad306..a8845f1975 100644 --- a/ethdb/memorydb/memorydb_test.go +++ b/ethdb/memorydb/memorydb_test.go @@ -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() + } +}