| 1 |
// Copyright 2017 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package runtime_test |
| 6 |
|
| 7 |
import ( |
| 8 |
. "runtime" |
| 9 |
"strconv" |
| 10 |
"testing" |
| 11 |
) |
| 12 |
|
| 13 |
func BenchmarkFastrand(b *testing.B) { |
| 14 |
b.RunParallel(func(pb *testing.PB) { |
| 15 |
for pb.Next() { |
| 16 |
Fastrand() |
| 17 |
} |
| 18 |
}) |
| 19 |
} |
| 20 |
|
| 21 |
func BenchmarkFastrandHashiter(b *testing.B) { |
| 22 |
var m = make(map[int]int, 10) |
| 23 |
for i := 0; i < 10; i++ { |
| 24 |
m[i] = i |
| 25 |
} |
| 26 |
b.RunParallel(func(pb *testing.PB) { |
| 27 |
for pb.Next() { |
| 28 |
for range m { |
| 29 |
break |
| 30 |
} |
| 31 |
} |
| 32 |
}) |
| 33 |
} |
| 34 |
|
| 35 |
var sink32 uint32 |
| 36 |
|
| 37 |
func BenchmarkFastrandn(b *testing.B) { |
| 38 |
for n := uint32(2); n <= 5; n++ { |
| 39 |
b.Run(strconv.Itoa(int(n)), func(b *testing.B) { |
| 40 |
for i := 0; i < b.N; i++ { |
| 41 |
sink32 = Fastrandn(n) |
| 42 |
} |
| 43 |
}) |
| 44 |
} |
| 45 |
} |