BenchmarkExtractStakeScriptHashV0 --------------------------------- v0_complex_non_standard 226793582 5.253 ns/op v0_stake_submission_p2sh 372232682 3.233 ns/op v0_stake_gen_p2sh 305602378 3.979 ns/op v0_stake_revoke_p2sh 201691552 5.064 ns/op v0_stake_change_p2sh 209401243 5.687 ns/op v0_treasury_generation_p2sh 221794405 5.419 ns/op
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
// Copyright (c) 2021 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package stdscript
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// BenchmarkExtractStakePubKeyHashV0 benchmarks the performance of attempting to
|
|
// extract public key hashes from various version 0 stake-tagged public key
|
|
// scripts.
|
|
func BenchmarkExtractStakePubKeyHashV0(b *testing.B) {
|
|
counts := make(map[ScriptType]int)
|
|
benches := makeBenchmarks(func(test scriptTest) bool {
|
|
// Limit to one of each script type.
|
|
counts[test.wantType]++
|
|
return counts[test.wantType] == 1 &&
|
|
(test.wantType == STStakeSubmissionPubKeyHash ||
|
|
test.wantType == STStakeGenPubKeyHash ||
|
|
test.wantType == STStakeRevocationPubKeyHash ||
|
|
test.wantType == STStakeChangePubKeyHash ||
|
|
test.wantType == STTreasuryGenPubKeyHash)
|
|
})
|
|
|
|
for _, bench := range benches {
|
|
b.Run(bench.name, func(b *testing.B) {
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
ExtractStakePubKeyHashV0(bench.script)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// BenchmarkExtractStakeScriptHashV0 benchmarks the performance of attempting to
|
|
// extract script hashes from various version 0 stake-tagged public key scripts.
|
|
func BenchmarkExtractStakeScriptHashV0(b *testing.B) {
|
|
counts := make(map[ScriptType]int)
|
|
benches := makeBenchmarks(func(test scriptTest) bool {
|
|
// Limit to one of each script type.
|
|
counts[test.wantType]++
|
|
return counts[test.wantType] == 1 &&
|
|
(test.wantType == STStakeSubmissionScriptHash ||
|
|
test.wantType == STStakeGenScriptHash ||
|
|
test.wantType == STStakeRevocationScriptHash ||
|
|
test.wantType == STStakeChangeScriptHash ||
|
|
test.wantType == STTreasuryGenScriptHash)
|
|
})
|
|
|
|
for _, bench := range benches {
|
|
b.Run(bench.name, func(b *testing.B) {
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
ExtractStakeScriptHashV0(bench.script)
|
|
}
|
|
})
|
|
}
|
|
}
|