primitives: Add work calc benchmark.

The following is a comparison between the existing implementation in the
blockchain/standalone module with big integers (old) and the new
implementation (new) averaging 10 runs each:

name       old time/op     new time/op     delta
---------------------------------------------------------------------
CalcWork   638ns ± 1%      59ns ± 1%       -90.78%  (p=0.000 n=10+10)

name       old allocs/op   new allocs/op   delta
----------------------------------------------------------------------
CalcWork   7.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
This commit is contained in:
Dave Collins 2021-11-07 16:29:29 -06:00
parent ecf6c6313e
commit 44204ac2ff
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2

View File

@ -30,3 +30,13 @@ func BenchmarkUint256ToDiffBits(b *testing.B) {
Uint256ToDiffBits(n)
}
}
// BenchmarkCalcWork benchmarks calculating a work value from difficulty bits.
func BenchmarkCalcWork(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
const input = 0x1b01330e
CalcWork(input)
}
}