1 // Copyright (c) 2015-2016 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
12 "github.com/btcsuite/btcd/chaincfg"
13 "github.com/btcsuite/btcd/database"
14 "github.com/btcsuite/btcutil"
17 // BenchmarkBlockHeader benchmarks how long it takes to load the mainnet genesis
19 func BenchmarkBlockHeader(b *testing.B) {
20 // Start by creating a new database and populating it with the mainnet
22 dbPath := filepath.Join(os.TempDir(), "ffldb-benchblkhdr")
23 _ = os.RemoveAll(dbPath)
24 db, err := database.Create("ffldb", dbPath, blockDataNet)
28 defer os.RemoveAll(dbPath)
30 err = db.Update(func(tx database.Tx) error {
31 block := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
32 return tx.StoreBlock(block)
40 err = db.View(func(tx database.Tx) error {
41 blockHash := chaincfg.MainNetParams.GenesisHash
42 for i := 0; i < b.N; i++ {
43 _, err := tx.FetchBlockHeader(blockHash)
54 // Don't benchmark teardown.
58 // BenchmarkBlockHeader benchmarks how long it takes to load the mainnet genesis
60 func BenchmarkBlock(b *testing.B) {
61 // Start by creating a new database and populating it with the mainnet
63 dbPath := filepath.Join(os.TempDir(), "ffldb-benchblk")
64 _ = os.RemoveAll(dbPath)
65 db, err := database.Create("ffldb", dbPath, blockDataNet)
69 defer os.RemoveAll(dbPath)
71 err = db.Update(func(tx database.Tx) error {
72 block := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
73 return tx.StoreBlock(block)
81 err = db.View(func(tx database.Tx) error {
82 blockHash := chaincfg.MainNetParams.GenesisHash
83 for i := 0; i < b.N; i++ {
84 _, err := tx.FetchBlock(blockHash)
95 // Don't benchmark teardown.