Skip to content

Commit

Permalink
primitives: Add subsidy calc benchmarks.
Browse files Browse the repository at this point in the history
CalcSubsidyCacheSparse   26023311   45.99 ns/op   0 B/op   0 allocs/op
CalcWorkSubsidy          21051818   52.12 ns/op   0 B/op   0 allocs/op
CalcStakeVoteSubsidy     22216708   53.44 ns/op   0 B/op   0 allocs/op
CalcTreasurySubsidy      22610749   49.78 ns/op   0 B/op   0 allocs/op
  • Loading branch information
davecgh committed Apr 12, 2022
1 parent a36ad51 commit 41230c6
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions internal/staging/primitives/subsidy_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2019-2022 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package primitives

import (
"testing"
)

// BenchmarkCalcSubsidyCacheSparse benchmarks calculating the subsidy for
// various heights with a sparse access pattern.
func BenchmarkCalcSubsidyCacheSparse(b *testing.B) {
mockParams := mockMainNetParams()
reductionInterval := mockParams.SubsidyReductionIntervalBlocks()

b.ResetTimer()
b.ReportAllocs()
const numIterations = 100
for i := 0; i < b.N; i += (numIterations * 5) {
cache := NewSubsidyCache(mockParams)
for j := int64(0); j < numIterations; j++ {
cache.CalcBlockSubsidy(reductionInterval * (10000 + j))
cache.CalcBlockSubsidy(reductionInterval * 1)
cache.CalcBlockSubsidy(reductionInterval * 5)
cache.CalcBlockSubsidy(reductionInterval * 25)
cache.CalcBlockSubsidy(reductionInterval * 13)
}
}
}

// BenchmarkCalcWorkSubsidy benchmarks calculating the work subsidy proportion
// for various heights with a sparse access pattern, varying numbers of votes,
// and with and without DCP0010 active.
func BenchmarkCalcWorkSubsidy(b *testing.B) {
mockParams := mockMainNetParams()
reductionInterval := mockParams.SubsidyReductionIntervalBlocks()

b.ResetTimer()
b.ReportAllocs()
const numIterations = 100
for i := 0; i < b.N; i += (numIterations * 5) {
cache := NewSubsidyCache(mockParams)
for j := int64(0); j < numIterations; j++ {
cache.CalcWorkSubsidy(reductionInterval*(10000+j), 5, true)
cache.CalcWorkSubsidy(reductionInterval*1, 4, false)
cache.CalcWorkSubsidy(reductionInterval*5, 3, false)
cache.CalcWorkSubsidy(reductionInterval*25, 4, true)
cache.CalcWorkSubsidy(reductionInterval*13, 5, false)
}
}
}

// BenchmarkCalcStakeVoteSubsidy benchmarks calculating the stake vote subsidy
// proportion for various heights with a sparse access pattern with and without
// DCP0010 active.
func BenchmarkCalcStakeVoteSubsidy(b *testing.B) {
mockParams := mockMainNetParams()
reductionInterval := mockParams.SubsidyReductionIntervalBlocks()

b.ResetTimer()
b.ReportAllocs()
const numIterations = 100
for i := 0; i < b.N; i += (numIterations * 5) {
cache := NewSubsidyCache(mockParams)
for j := int64(0); j < numIterations; j++ {
cache.CalcStakeVoteSubsidy(reductionInterval*(10000+j), true)
cache.CalcStakeVoteSubsidy(reductionInterval*1, false)
cache.CalcStakeVoteSubsidy(reductionInterval*5, false)
cache.CalcStakeVoteSubsidy(reductionInterval*25, true)
cache.CalcStakeVoteSubsidy(reductionInterval*13, false)
}
}
}

// BenchmarkCalcTreasurySubsidy benchmarks calculating the treasury subsidy
// proportion for various heights with a sparse access pattern, varying numbers
// of votes, and with and without DCP0006 active.
func BenchmarkCalcTreasurySubsidy(b *testing.B) {
mockParams := mockMainNetParams()
reductionInterval := mockParams.SubsidyReductionIntervalBlocks()

b.ResetTimer()
b.ReportAllocs()
const numIterations = 100
for i := 0; i < b.N; i += (numIterations * 5) {
cache := NewSubsidyCache(mockParams)
for j := int64(0); j < numIterations; j++ {
cache.CalcTreasurySubsidy(reductionInterval*(10000+j), 5, true)
cache.CalcTreasurySubsidy(reductionInterval*1, 4, false)
cache.CalcTreasurySubsidy(reductionInterval*5, 3, false)
cache.CalcTreasurySubsidy(reductionInterval*25, 4, true)
cache.CalcTreasurySubsidy(reductionInterval*13, 5, true)
}
}
}

0 comments on commit 41230c6

Please sign in to comment.