From 4683c8a9d2e67bf21bfc867b055a834aec6a4836 Mon Sep 17 00:00:00 2001 From: Hans Moog <hm@mkjc.net> Date: Thu, 26 Dec 2019 01:19:01 +0100 Subject: [PATCH] Feat: benchmark: 50000 data TPS (complete parsing + validating) --- .../transaction/test/transaction_test.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/binary/transaction/test/transaction_test.go b/packages/binary/transaction/test/transaction_test.go index 4ff8aa67..c04c62b4 100644 --- a/packages/binary/transaction/test/transaction_test.go +++ b/packages/binary/transaction/test/transaction_test.go @@ -22,6 +22,42 @@ import ( "github.com/stretchr/testify/assert" ) +func BenchmarkVerifyDataTransactions(b *testing.B) { + transactions := make([][]byte, b.N) + for i := 0; i < b.N; i++ { + tx := transaction.New(transaction.EmptyId, transaction.EmptyId, identity.Generate(), data.New([]byte("some data"))) + + if marshaledTransaction, err := tx.MarshalBinary(); err != nil { + b.Error(err) + } else { + transactions[i] = marshaledTransaction + } + } + + var wg sync.WaitGroup + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + wg.Add(1) + + currentIndex := i + if err := ants.Submit(func() { + if tx, err := transaction.FromBytes(transactions[currentIndex]); err != nil { + b.Error(err) + } else { + tx.VerifySignature() + } + + wg.Done() + }); err != nil { + b.Error(err) + } + } + + wg.Wait() +} + func BenchmarkVerifyValueTransactions(b *testing.B) { keyPairOfSourceAddress := ed25119.GenerateKeyPair() keyPairOfTargetAddress := ed25119.GenerateKeyPair() -- GitLab