From: Rémy Oudompheng Date: Sat, 20 Jul 2013 21:31:51 +0000 (+0200) Subject: regexp: use a very fast random generator for benchmarks. X-Git-Tag: go1.2rc2~983 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=21b9d1473838b34911629e754f5cd2165411c1f4;p=gostls13.git regexp: use a very fast random generator for benchmarks. 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 --- diff --git a/src/pkg/regexp/exec_test.go b/src/pkg/regexp/exec_test.go index f6fcd4be4a..555e06e826 100644 --- a/src/pkg/regexp/exec_test.go +++ b/src/pkg/regexp/exec_test.go @@ -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