2015-05-01 01:28:01 -05:00
|
|
|
// Copyright (c) 2015 The btcsuite developers
|
2015-03-10 00:41:19 -05:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-08-19 19:21:36 -05:00
|
|
|
package blockchain
|
2015-03-10 00:41:19 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-12-24 16:43:16 -08:00
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
2023-05-05 22:19:54 +09:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2015-03-10 00:41:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// BenchmarkIsCoinBase performs a simple benchmark against the IsCoinBase
|
|
|
|
// function.
|
|
|
|
func BenchmarkIsCoinBase(b *testing.B) {
|
|
|
|
tx, _ := btcutil.NewBlock(&Block100000).Tx(1)
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2017-08-19 19:21:36 -05:00
|
|
|
IsCoinBase(tx)
|
2015-03-10 00:41:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BenchmarkIsCoinBaseTx performs a simple benchmark against the IsCoinBaseTx
|
|
|
|
// function.
|
|
|
|
func BenchmarkIsCoinBaseTx(b *testing.B) {
|
|
|
|
tx := Block100000.Transactions[1]
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2017-08-19 19:21:36 -05:00
|
|
|
IsCoinBaseTx(tx)
|
2015-03-10 00:41:19 -05:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 22:19:54 +09:00
|
|
|
|
|
|
|
func BenchmarkUtxoFetchMap(b *testing.B) {
|
|
|
|
block := Block100000
|
|
|
|
transactions := block.Transactions
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
needed := make(map[wire.OutPoint]struct{}, len(transactions))
|
|
|
|
for _, tx := range transactions[1:] {
|
|
|
|
for _, txIn := range tx.TxIn {
|
|
|
|
needed[txIn.PreviousOutPoint] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkUtxoFetchSlices(b *testing.B) {
|
|
|
|
block := Block100000
|
|
|
|
transactions := block.Transactions
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
needed := make([]wire.OutPoint, 0, len(transactions))
|
|
|
|
for _, tx := range transactions[1:] {
|
|
|
|
for _, txIn := range tx.TxIn {
|
|
|
|
needed = append(needed, txIn.PreviousOutPoint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-17 16:32:55 +09:00
|
|
|
|
|
|
|
func BenchmarkAncestor(b *testing.B) {
|
|
|
|
height := 1 << 19
|
|
|
|
blockNodes := chainedNodes(nil, height)
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
blockNodes[len(blockNodes)-1].Ancestor(0)
|
|
|
|
for j := 0; j <= 19; j++ {
|
|
|
|
blockNodes[len(blockNodes)-1].Ancestor(1 << j)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|