From 59fbc689e4cc9515ea758a65ad1c8230194ed7be Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 23 Aug 2022 09:34:00 +0300 Subject: [PATCH] vm/bench: extend refcounter benchmarks Adding an array multiple times leads to the fast update via `IncRC`. This hides the allocation that is there on the first addition. In this commit add another benchmark which measures Add/Remove together, to ensure that `switch` in `refCounter.Add` is entered. Benchmark results are meaningful, because `Add`/`Remove` have almost identical implementation. Signed-off-by: Evgeniy Stratonikov --- pkg/vm/ref_counter_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/vm/ref_counter_test.go b/pkg/vm/ref_counter_test.go index f0e63b318..8da020671 100644 --- a/pkg/vm/ref_counter_test.go +++ b/pkg/vm/ref_counter_test.go @@ -55,3 +55,14 @@ func BenchmarkRefCounter_Add(b *testing.B) { rc.Add(a) } } + +func BenchmarkRefCounter_AddRemove(b *testing.B) { + a := stackitem.NewArray([]stackitem.Item{}) + rc := newRefCounter() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + rc.Add(a) + rc.Remove(a) + } +}