mirror of
https://github.com/golang/go
synced 2024-11-22 03:14:41 -07:00
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
This commit is contained in:
parent
87976e72a8
commit
21b9d14738
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user