From 403a4b75deb52de5e75ef72b1f605b83c974518e Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Thu, 5 Aug 2021 13:14:43 +0300 Subject: [PATCH] state/test: add benchmark for `NEP17TransferLog.Append` Signed-off-by: Evgeniy Stratonikov --- pkg/core/state/nep17_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/core/state/nep17_test.go b/pkg/core/state/nep17_test.go index b21d1cdf7..514cbe61a 100644 --- a/pkg/core/state/nep17_test.go +++ b/pkg/core/state/nep17_test.go @@ -38,6 +38,26 @@ func TestNEP17TransferLog_Append(t *testing.T) { require.True(t, cont) } +func BenchmarkNEP17TransferLog_Append(b *testing.B) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + ts := make([]*NEP17Transfer, NEP17TransferBatchSize) + for i := range ts { + ts[i] = randomTransfer(r) + } + + lg := new(NEP17TransferLog) + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for _, tr := range ts { + err := lg.Append(tr) + if err != nil { + b.FailNow() + } + } + } +} + func TestNEP17Transfer_DecodeBinary(t *testing.T) { expected := &NEP17Transfer{ Asset: 123,