mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
4f98ec2f53
``` name old time/op new time/op delta RefCounter_Add-8 44.8ns ± 4% 11.7ns ± 3% -73.94% (p=0.000 n=10+10) ``` Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
43 lines
845 B
Go
43 lines
845 B
Go
package vm
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRefCounter_Add(t *testing.T) {
|
|
r := newRefCounter()
|
|
|
|
require.Equal(t, 0, int(*r))
|
|
|
|
r.Add(stackitem.Null{})
|
|
require.Equal(t, 1, int(*r))
|
|
|
|
r.Add(stackitem.Null{})
|
|
require.Equal(t, 2, int(*r)) // count scalar items twice
|
|
|
|
arr := stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte{1}), stackitem.NewBool(false)})
|
|
r.Add(arr)
|
|
require.Equal(t, 5, int(*r)) // array + 2 elements
|
|
|
|
r.Add(arr)
|
|
require.Equal(t, 6, int(*r)) // count only array
|
|
|
|
r.Remove(arr)
|
|
require.Equal(t, 5, int(*r))
|
|
|
|
r.Remove(arr)
|
|
require.Equal(t, 2, int(*r))
|
|
}
|
|
|
|
func BenchmarkRefCounter_Add(b *testing.B) {
|
|
a := stackitem.NewArray(nil)
|
|
rc := newRefCounter()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
rc.Add(a)
|
|
}
|
|
}
|