github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/test/performance/mining_test.go (about)

     1  package performance
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/bytom/bytom/account"
     8  	"github.com/bytom/bytom/mining"
     9  	"github.com/bytom/bytom/test"
    10  	dbm "github.com/bytom/bytom/database/leveldb"
    11  )
    12  
    13  // Function NewBlockTemplate's benchmark - 0.05s
    14  func BenchmarkNewBlockTpl(b *testing.B) {
    15  	testDB := dbm.NewDB("testdb", "leveldb", "temp")
    16  	defer os.RemoveAll("temp")
    17  
    18  	chain, _, txPool, err := test.MockChain(testDB)
    19  	if err != nil {
    20  		b.Fatal(err)
    21  	}
    22  	accountManager := account.NewManager(testDB, chain)
    23  
    24  	b.ResetTimer()
    25  	for i := 0; i < b.N; i++ {
    26  		mining.NewBlockTemplate(chain, txPool, accountManager)
    27  	}
    28  }