From 8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8 Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Thu, 30 Aug 2018 15:09:15 +0800 Subject: core: tune total ordering performance (#81) - Replace map with slice Compared to slice, accessing to map is slower and the memory usage is inefficient. --- core/test/blocks-generator_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'core/test/blocks-generator_test.go') diff --git a/core/test/blocks-generator_test.go b/core/test/blocks-generator_test.go index 43e994f..5c85fbd 100644 --- a/core/test/blocks-generator_test.go +++ b/core/test/blocks-generator_test.go @@ -39,9 +39,10 @@ func (s *BlocksGeneratorTestCase) TestGenerate() { db, err := blockdb.NewMemBackedBlockDB() s.Require().Nil(err) - err = gen.Generate( + validators, err := gen.Generate( validatorCount, blockCount, nil, db) s.Require().Nil(err) + s.Require().Len(validators, validatorCount) // Load all blocks in that database for further checking. iter, err := db.GetAll() @@ -114,8 +115,10 @@ func (s *BlocksGeneratorTestCase) TestGenerateWithMaxAckCount() { // Generate with 0 acks. db, err := blockdb.NewMemBackedBlockDB() req.Nil(err) - req.Nil(gen.Generate( - validatorCount, blockCount, MaxAckingCountGenerator(0), db)) + validators, err := gen.Generate( + validatorCount, blockCount, MaxAckingCountGenerator(0), db) + req.Nil(err) + req.Len(validators, validatorCount) // Load blocks to check their acking count. iter, err := db.GetAll() req.Nil(err) @@ -134,9 +137,11 @@ func (s *BlocksGeneratorTestCase) TestGenerateWithMaxAckCount() { // Generate with acks as many as possible. db, err = blockdb.NewMemBackedBlockDB() req.Nil(err) - req.Nil(gen.Generate( + validators, err = gen.Generate( validatorCount, blockCount, MaxAckingCountGenerator( - validatorCount), db)) + validatorCount), db) + req.Nil(err) + req.Len(validators, validatorCount) // Load blocks to verify the average acking count. totalAckingCount := 0 totalBlockCount := 0 -- cgit v1.2.3