From 66e2409d9b429ef2bf4aa3ef119a7dccade0915b Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 6 Nov 2021 16:07:24 -0500 Subject: [PATCH] uint256: Add is odd 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 ------------------------------------------------------------------ IsOdd 3.62ns ± 4% 1.64ns ± 1% -54.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta --------------------------------------------------------- IsOdd 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 | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/staging/primitives/uint256/uint256_bench_test.go b/internal/staging/primitives/uint256/uint256_bench_test.go index f93ed5a9..3cfe76d7 100644 --- a/internal/staging/primitives/uint256/uint256_bench_test.go +++ b/internal/staging/primitives/uint256/uint256_bench_test.go @@ -257,6 +257,34 @@ func BenchmarkBigIntIsZero(b *testing.B) { } } +// BenchmarkUint256IsOdd benchmarks determining if an unsigned 256-bit integer +// is odd with the specialized type. +func BenchmarkUint256IsOdd(b *testing.B) { + vals := randBenchVals + + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i += len(vals) { + for j := 0; j < len(vals); j++ { + noElideBool = vals[j].n1.IsOdd() + } + } +} + +// BenchmarkBigIntIsOdd benchmarks determining if an unsigned 256-bit integer is +// odd with stdlib big integers. +func BenchmarkBigIntIsOdd(b *testing.B) { + vals := randBenchVals + + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i += len(vals) { + for j := 0; j < len(vals); j++ { + noElideBool = vals[j].bigN1.Bit(0) == 1 + } + } +} + // BenchmarkUint256Eq benchmarks determining equality between two unsigned // 256-bit integers with the specialized type. func BenchmarkUint256Eq(b *testing.B) {