Commit 21b9d147 authored by Rémy Oudompheng's avatar Rémy Oudompheng

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
parent 87976e72
......@@ -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
......
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