]> Cypherpunks repositories - gostls13.git/commitdiff
sort: use a very fast random generator for benchmarks
authorDave Cheney <dave@cheney.net>
Thu, 29 Aug 2013 03:21:21 +0000 (13:21 +1000)
committerDave Cheney <dave@cheney.net>
Thu, 29 Aug 2013 03:21:21 +0000 (13:21 +1000)
Adapted from https://golang.org/cl/11564044.

Fixes breakage of darwin-amd64-race builder.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13352045

src/pkg/sort/sort_test.go

index 3b705d7a244ec9e2e12c1bfa10f2f89485695c49..6c36f30e0eebba98bc41e7ed50e45064498ee33f 100644 (file)
@@ -520,10 +520,16 @@ func TestCountSortOps(t *testing.T)   { countOps(t, Sort, "Sort  ") }
 func bench(b *testing.B, size int, algo func(Interface), name string) {
        b.StopTimer()
        data := make(intPairs, size)
+       x := ^uint32(0)
        for i := 0; i < b.N; i++ {
                for n := size - 3; n <= size+3; n++ {
                        for i := 0; i < len(data); i++ {
-                               data[i].a = rand.Intn(n / 5)
+                               x += x
+                               x ^= 1
+                               if int32(x) < 0 {
+                                       x ^= 0x88888eef
+                               }
+                               data[i].a = int(x % uint32(n/5))
                        }
                        data.initB()
                        b.StartTimer()