From 44204ac2fff805aaad34a586f49593faf0bceafc Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 7 Nov 2021 16:29:29 -0600 Subject: [PATCH] primitives: Add work calc benchmark. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- internal/staging/primitives/pow_bench_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/staging/primitives/pow_bench_test.go b/internal/staging/primitives/pow_bench_test.go index 6cf98ae8..1587da83 100644 --- a/internal/staging/primitives/pow_bench_test.go +++ b/internal/staging/primitives/pow_bench_test.go @@ -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) + } +}