mirror of
https://github.com/golang/go
synced 2024-11-20 08:04:42 -07:00
math: fix Abs, Copysign and Signbit benchmarks
CL 62250 makes constant folding a bit more aggressive and these benchmarks were optimized away. This CL adds some indirection to the function arguments to stop them being folded. The Copysign benchmark is a bit faster because I've left one argument as a constant and it can be partially folded. old CL 62250 this CL Copysign 1.24ns ± 0% 0.34ns ± 2% 1.02ns ± 2% Abs 0.67ns ± 0% 0.35ns ± 3% 0.67ns ± 0% Signbit 0.87ns ± 0% 0.35ns ± 2% 0.87ns ± 1% Change-Id: I9604465a87d7aa29f4bd6009839c8ee354be3cd7 Reviewed-on: https://go-review.googlesource.com/62450 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
d8ae2156fe
commit
ffb4708d1b
@ -3068,10 +3068,12 @@ func BenchmarkCeil(b *testing.B) {
|
||||
GlobalF = x
|
||||
}
|
||||
|
||||
var copysignNeg = -1.0
|
||||
|
||||
func BenchmarkCopysign(b *testing.B) {
|
||||
x := 0.0
|
||||
for i := 0; i < b.N; i++ {
|
||||
x = Copysign(.5, -1)
|
||||
x = Copysign(.5, copysignNeg)
|
||||
}
|
||||
GlobalF = x
|
||||
}
|
||||
@ -3164,10 +3166,12 @@ func BenchmarkExp2Go(b *testing.B) {
|
||||
GlobalF = x
|
||||
}
|
||||
|
||||
var absPos = .5
|
||||
|
||||
func BenchmarkAbs(b *testing.B) {
|
||||
x := 0.0
|
||||
for i := 0; i < b.N; i++ {
|
||||
x = Abs(.5)
|
||||
x = Abs(absPos)
|
||||
}
|
||||
GlobalF = x
|
||||
|
||||
@ -3417,10 +3421,12 @@ func BenchmarkRemainder(b *testing.B) {
|
||||
GlobalF = x
|
||||
}
|
||||
|
||||
var signbitPos = 2.5
|
||||
|
||||
func BenchmarkSignbit(b *testing.B) {
|
||||
x := false
|
||||
for i := 0; i < b.N; i++ {
|
||||
x = Signbit(2.5)
|
||||
x = Signbit(signbitPos)
|
||||
}
|
||||
GlobalB = x
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user