From 34278a750972156dd46f9aa2718759236534a68c Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 21 Jul 2025 17:22:52 +0800 Subject: [PATCH] triedb/pathdb: add BenchmarkBlockWriterAppend Signed-off-by: jsvisa --- triedb/pathdb/history_index_block_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/triedb/pathdb/history_index_block_test.go b/triedb/pathdb/history_index_block_test.go index 7b0e362c66..c251cea2ec 100644 --- a/triedb/pathdb/history_index_block_test.go +++ b/triedb/pathdb/history_index_block_test.go @@ -232,3 +232,22 @@ func BenchmarkParseIndexBlock(b *testing.B) { } } } + +// BenchmarkBlockWriterAppend benchmarks the performance of indexblock.writer +func BenchmarkBlockWriterAppend(b *testing.B) { + b.ReportAllocs() + b.ResetTimer() + + desc := newIndexBlockDesc(0) + writer, _ := newBlockWriter(nil, desc) + + for i := 0; i < b.N; i++ { + if writer.full() { + desc = newIndexBlockDesc(0) + writer, _ = newBlockWriter(nil, desc) + } + if err := writer.append(writer.desc.max + 1); err != nil { + b.Error(err) + } + } +}