From 3ce3e3305627402fdedf98d738baa2e88dd5bf89 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 6 Nov 2021 16:07:31 -0500 Subject: [PATCH] uint256: Add bitwise not benchmarks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following is a comparison between stdlib big integers (old) and the specialized type (new) averaging 10 runs each: name old time/op new time/op delta ----------------------------------------------------------------- Not 25.4ns ± 2% 3.3ns ± 2% -86.79% (p=0.000 n=10+10) name old allocs/op new allocs/op delta -------------------------------------------------------- Not 0.00 0.00 ~ (all equal) This is part of a series of commits to fully implement the uint256 package. --- .../primitives/uint256/uint256_bench_test.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/internal/staging/primitives/uint256/uint256_bench_test.go b/internal/staging/primitives/uint256/uint256_bench_test.go index 072b46fe..45d5c04a 100644 --- a/internal/staging/primitives/uint256/uint256_bench_test.go +++ b/internal/staging/primitives/uint256/uint256_bench_test.go @@ -1016,3 +1016,35 @@ func BenchmarkBigIntRsh(b *testing.B) { }) } } + +// BenchmarkUint256Not benchmarks computing the bitwise not of an unsigned +// 256-bit integer with the specialized type. +func BenchmarkUint256Not(b *testing.B) { + n := new(Uint256) + vals := randBenchVals + + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i += len(vals) { + for j := 0; j < len(vals); j++ { + n.Set(vals[j].n1) + n.Not() + } + } +} + +// BenchmarkBigIntNot benchmarks computing the bitwise not of an unsigned +// 256-bit integer with stdlib big integers. +func BenchmarkBigIntNot(b *testing.B) { + n := new(big.Int) + vals := randBenchVals + + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i += len(vals) { + for j := 0; j < len(vals); j++ { + n.Set(vals[j].bigN1) // For fair comparison. + n.Not(n) + } + } +}