summaryrefslogtreecommitdiff
path: root/src/pkg/rand/rand_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-12-15 17:21:34 -0800
committerRuss Cox <rsc@golang.org>2009-12-15 17:21:34 -0800
commit5cefd2a941981a41a13823202ba417960c3bb67b (patch)
treeba976eafb17f1f689ab4ac654c02fdda4e62e227 /src/pkg/rand/rand_test.go
parente7eda89e94417da96c6c9c311680ad0fde40b849 (diff)
downloadgolang-5cefd2a941981a41a13823202ba417960c3bb67b.tar.gz
rand: add explicit Int31n to avoid 64-bit divide on 32-bit machines
use Int31n in Intn when possible. Fixes issue 390. (using 8g) Intn1000 50000000 38 ns/op Int31n1000 50000000 39 ns/op Int63n1000 20000000 114 ns/op R=r CC=golang-dev, skybrian http://codereview.appspot.com/180054
Diffstat (limited to 'src/pkg/rand/rand_test.go')
-rw-r--r--src/pkg/rand/rand_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/pkg/rand/rand_test.go b/src/pkg/rand/rand_test.go
index b90c69db7..786831517 100644
--- a/src/pkg/rand/rand_test.go
+++ b/src/pkg/rand/rand_test.go
@@ -327,3 +327,24 @@ func BenchmarkInt63Unthreadsafe(b *testing.B) {
r.Int63()
}
}
+
+func BenchmarkIntn1000(b *testing.B) {
+ r := New(NewSource(1))
+ for n := b.N; n > 0; n-- {
+ r.Intn(1000)
+ }
+}
+
+func BenchmarkInt63n1000(b *testing.B) {
+ r := New(NewSource(1))
+ for n := b.N; n > 0; n-- {
+ r.Int63n(1000)
+ }
+}
+
+func BenchmarkInt31n1000(b *testing.B) {
+ r := New(NewSource(1))
+ for n := b.N; n > 0; n-- {
+ r.Int31n(1000)
+ }
+}