-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
primitives: Add subsidy calc benchmarks.
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
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |