Commit 1a0a09da authored by Rémy Oudompheng's avatar Rémy Oudompheng

math/rand: avoid use of math.Pow in tests.

The use of math.Pow for mere squaring can be extremely
slow on soft-float ARM. Even on systems with hardware
floating-point, a speedup in test duration is observed.

On amd64
Before: ok      math/rand       2.009s
After:  ok      math/rand       0.340s

Fixes #3740.

R=dave, golang-dev, r, r
CC=golang-dev
https://golang.org/cl/6348061
parent 55cc1ff7
......@@ -57,16 +57,13 @@ func (this *statsResults) checkSimilarDistribution(expected *statsResults) error
func getStatsResults(samples []float64) *statsResults {
res := new(statsResults)
var sum float64
for i := range samples {
sum += samples[i]
var sum, squaresum float64
for _, s := range samples {
sum += s
squaresum += s * s
}
res.mean = sum / float64(len(samples))
var devsum float64
for i := range samples {
devsum += math.Pow(samples[i]-res.mean, 2)
}
res.stddev = math.Sqrt(devsum / float64(len(samples)))
res.stddev = math.Sqrt(squaresum/float64(len(samples)) - res.mean*res.mean)
return res
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment