diff --git a/vochain/indexer/bench_test.go b/vochain/indexer/bench_test.go index 4303b5594..71bc10db2 100644 --- a/vochain/indexer/bench_test.go +++ b/vochain/indexer/bench_test.go @@ -1,15 +1,12 @@ package indexer import ( - "fmt" "math/big" "sync" "testing" - "time" qt "github.com/frankban/quicktest" "go.vocdoni.io/dvote/crypto/ethereum" - "go.vocdoni.io/dvote/log" "go.vocdoni.io/dvote/test/testcommon/testutil" "go.vocdoni.io/dvote/util" "go.vocdoni.io/dvote/vochain" @@ -126,68 +123,3 @@ func BenchmarkIndexer(b *testing.B) { lastTxs = curTxs } } - -func BenchmarkFetchTx(b *testing.B) { - numTxs := 1000 - app := vochain.TestBaseApplication(b) - - idx := newTestIndexer(b, app, true) - - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - for j := 0; j < numTxs; j++ { - idx.OnNewTx(&vochaintx.Tx{TxID: util.Random32()}, uint32(i), int32(j)) - } - err := idx.Commit(uint32(i)) - qt.Assert(b, err, qt.IsNil) - - time.Sleep(time.Second * 2) - - startTime := time.Now() - for j := 0; j < numTxs; j++ { - _, err = idx.GetTransaction(uint64((i * numTxs) + j + 1)) - qt.Assert(b, err, qt.IsNil) - } - log.Infof("fetched %d transactions (out of %d total) by index, took %s", - numTxs, (i+1)*numTxs, time.Since(startTime)) - startTime = time.Now() - for j := 0; j < numTxs; j++ { - _, err = idx.GetTxHashReference([]byte(fmt.Sprintf("hash%d%d", i, j))) - qt.Assert(b, err, qt.IsNil) - } - log.Infof("fetched %d transactions (out of %d total) by hash, took %s", - numTxs, (i+1)*numTxs, time.Since(startTime)) - } -} - -func BenchmarkNewProcess(b *testing.B) { - app := vochain.TestBaseApplication(b) - - idx := newTestIndexer(b, app, true) - _ = idx // used via the callbacks; we want to benchmark it too - startTime := time.Now() - numProcesses := b.N - entityID := util.RandomBytes(20) - - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < numProcesses; i++ { - pid := util.RandomBytes(32) - if err := app.State.AddProcess(&models.Process{ - ProcessId: pid, - // EntityId: util.RandomBytes(20), - EntityId: entityID, - EnvelopeType: &models.EnvelopeType{EncryptedVotes: false}, - Status: models.ProcessStatus_READY, - BlockCount: 100000000, - VoteOptions: &models.ProcessVoteOptions{MaxCount: 3, MaxValue: 1}, - Mode: &models.ProcessMode{AutoStart: true}, - }); err != nil { - b.Fatal(err) - } - } - app.AdvanceTestBlock() - log.Infof("indexed %d new processes, took %s", - numProcesses, time.Since(startTime)) -}