File tree Expand file tree Collapse file tree 4 files changed +24
-20
lines changed
Expand file tree Collapse file tree 4 files changed +24
-20
lines changed Original file line number Diff line number Diff line change 11package lru
22
33import (
4- "crypto/rand"
5- "math"
6- "math/big"
74 "testing"
85)
96
10- func getRand (tb testing.TB ) int64 {
11- out , err := rand .Int (rand .Reader , big .NewInt (math .MaxInt64 ))
12- if err != nil {
13- tb .Fatal (err )
14- }
15- return out .Int64 ()
16- }
17-
187func Benchmark2Q_Rand (b * testing.B ) {
198 l , err := New2Q (8192 )
209 if err != nil {
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ func BenchmarkARC_Rand(b *testing.B) {
1818
1919 trace := make ([]int64 , b .N * 2 )
2020 for i := 0 ; i < b .N * 2 ; i ++ {
21- trace [i ] = rand . Int63 ( ) % 32768
21+ trace [i ] = getRand ( b ) % 32768
2222 }
2323
2424 b .ResetTimer ()
@@ -48,9 +48,9 @@ func BenchmarkARC_Freq(b *testing.B) {
4848 trace := make ([]int64 , b .N * 2 )
4949 for i := 0 ; i < b .N * 2 ; i ++ {
5050 if i % 2 == 0 {
51- trace [i ] = rand . Int63 ( ) % 16384
51+ trace [i ] = getRand ( b ) % 16384
5252 } else {
53- trace [i ] = rand . Int63 ( ) % 32768
53+ trace [i ] = getRand ( b ) % 32768
5454 }
5555 }
5656
@@ -80,8 +80,8 @@ func TestARC_RandomOps(t *testing.T) {
8080
8181 n := 200000
8282 for i := 0 ; i < n ; i ++ {
83- key := rand . Int63 ( ) % 512
84- r := rand . Int63 ( )
83+ key := getRand ( t ) % 512
84+ r := getRand ( t )
8585 switch r % 3 {
8686 case 0 :
8787 l .Add (key , key )
Original file line number Diff line number Diff line change 11package lru
22
33import (
4- "math/rand"
54 "testing"
65)
76
@@ -13,7 +12,7 @@ func BenchmarkLRU_Rand(b *testing.B) {
1312
1413 trace := make ([]int64 , b .N * 2 )
1514 for i := 0 ; i < b .N * 2 ; i ++ {
16- trace [i ] = rand . Int63 ( ) % 32768
15+ trace [i ] = getRand ( b ) % 32768
1716 }
1817
1918 b .ResetTimer ()
@@ -43,9 +42,9 @@ func BenchmarkLRU_Freq(b *testing.B) {
4342 trace := make ([]int64 , b .N * 2 )
4443 for i := 0 ; i < b .N * 2 ; i ++ {
4544 if i % 2 == 0 {
46- trace [i ] = rand . Int63 ( ) % 16384
45+ trace [i ] = getRand ( b ) % 16384
4746 } else {
48- trace [i ] = rand . Int63 ( ) % 32768
47+ trace [i ] = getRand ( b ) % 32768
4948 }
5049 }
5150
Original file line number Diff line number Diff line change 1+ package lru
2+
3+ import (
4+ "crypto/rand"
5+ "math"
6+ "math/big"
7+ "testing"
8+ )
9+
10+ func getRand (tb testing.TB ) int64 {
11+ out , err := rand .Int (rand .Reader , big .NewInt (math .MaxInt64 ))
12+ if err != nil {
13+ tb .Fatal (err )
14+ }
15+ return out .Int64 ()
16+ }
You can’t perform that action at this time.
0 commit comments