mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
55cc1ff721
commit
1a0a09dafe
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue