uint256: Add bitwise not benchmarks.

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.
This commit is contained in:
Dave Collins 2021-11-06 16:07:31 -05:00
parent a42b8c89bf
commit 3ce3e33056
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2

View File

@ -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)
}
}
}