Skip to content

Commit

Permalink
uint256: Add conversion from stdlib big int benchmark.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davecgh committed Nov 16, 2021
1 parent 9db96fa commit 8783f7f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/staging/primitives/uint256/uint256_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 8783f7f

Please sign in to comment.