]> Cypherpunks repositories - gostls13.git/commitdiff
regexp: use a very fast random generator for benchmarks.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Sat, 20 Jul 2013 21:31:51 +0000 (23:31 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Sat, 20 Jul 2013 21:31:51 +0000 (23:31 +0200)
Calls into math/rand are very slow, especially under race
detector because of heap accesses.

go test -bench . -run none -benchtime .1s
Before: 23.0s
After:  17.4s

Fixes #5837.

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

src/pkg/regexp/exec_test.go

index f6fcd4be4ac0dacba1d28fd0a79ddf1adc83053f..555e06e826dd8a2ea8e22b48a36b6a98dcf48af6 100644 (file)
@@ -9,7 +9,6 @@ import (
        "compress/bzip2"
        "fmt"
        "io"
-       "math/rand"
        "os"
        "path/filepath"
        "regexp/syntax"
@@ -643,11 +642,17 @@ func makeText(n int) []byte {
                return text[:n]
        }
        text = make([]byte, n)
+       x := ^uint32(0)
        for i := range text {
-               if rand.Intn(30) == 0 {
+               x += x
+               x ^= 1
+               if int32(x) < 0 {
+                       x ^= 0x88888eef
+               }
+               if x%31 == 0 {
                        text[i] = '\n'
                } else {
-                       text[i] = byte(rand.Intn(0x7E+1-0x20) + 0x20)
+                       text[i] = byte(x%(0x7E+1-0x20) + 0x20)
                }
        }
        return text