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 <evgeniy@nspcc.ru>
This commit is contained in:
Evgeniy Stratonikov 2022-08-23 09:34:00 +03:00
parent 4531f79a4b
commit 59fbc689e4

View file

@ -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)
}
}