From 8783f7fcc3928c3f861b304aee2e68fdbee4fb3a Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 6 Nov 2021 16:07:50 -0500 Subject: [PATCH] uint256: Add conversion from stdlib big int benchmark. The following shows the typical performance of converting a standard library big integer that has already been reduced modulo 2^256 to a uint256: Uint256SetBig 26944130 44.45 ns/op 0 B/op 0 allocs/op This is part of a series of commits to fully implement the uint256 package. --- .../primitives/uint256/uint256_bench_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/staging/primitives/uint256/uint256_bench_test.go b/internal/staging/primitives/uint256/uint256_bench_test.go index d2fa4c9a0c..9b4e4b7ef7 100644 --- a/internal/staging/primitives/uint256/uint256_bench_test.go +++ b/internal/staging/primitives/uint256/uint256_bench_test.go @@ -1307,3 +1307,19 @@ func BenchmarkUint256PutBig(b *testing.B) { } } } + +// BenchmarkUint256PutBig benchmarks converting a stdlib big integer to an +// unsigned 256-bit integer. +func BenchmarkUint256SetBig(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++ { + val := &vals[j] + n.SetBig(val.bigN1) + } + } +}