aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2025-05-14 12:46:28 -0700
committerKeith Randall <khr@golang.org>2025-05-15 14:24:16 -0700
commita88f093aaa35ae18aa02389624822101cbf231c0 (patch)
treed0fb43316339ff49e5d43eee7b92d0f54ce35933 /src/bytes
parent19f05770b05ef2a12692f522056ffb3bc23583ea (diff)
downloadgo-a88f093aaa35ae18aa02389624822101cbf231c0.tar.xz
strings,bytes: make benchmark work deterministic
It's hard to compare two different runs of a benchmark if they are doing different amounts of work. Change-Id: I5d6845f3d11bb10136f745e6207d5f683612276d Reviewed-on: https://go-review.googlesource.com/c/go/+/672895 Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/bytes_test.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go
index 14b52a8035..0f6cf4993a 100644
--- a/src/bytes/bytes_test.go
+++ b/src/bytes/bytes_test.go
@@ -2128,8 +2128,9 @@ func TestContainsFunc(t *testing.T) {
var makeFieldsInput = func() []byte {
x := make([]byte, 1<<20)
// Input is ~10% space, ~10% 2-byte UTF-8, rest ASCII non-space.
+ r := rand.New(rand.NewSource(99))
for i := range x {
- switch rand.Intn(10) {
+ switch r.Intn(10) {
case 0:
x[i] = ' '
case 1:
@@ -2148,8 +2149,9 @@ var makeFieldsInput = func() []byte {
var makeFieldsInputASCII = func() []byte {
x := make([]byte, 1<<20)
// Input is ~10% space, rest ASCII non-space.
+ r := rand.New(rand.NewSource(99))
for i := range x {
- if rand.Intn(10) == 0 {
+ if r.Intn(10) == 0 {
x[i] = ' '
} else {
x[i] = 'x'
@@ -2246,8 +2248,9 @@ func makeBenchInputHard() []byte {
"hello", "world",
}
x := make([]byte, 0, 1<<20)
+ r := rand.New(rand.NewSource(99))
for {
- i := rand.Intn(len(tokens))
+ i := r.Intn(len(tokens))
if len(x)+len(tokens[i]) >= 1<<20 {
break
}