File tree 4 files changed +24
-20
lines changed
4 files changed +24
-20
lines changed Original file line number Diff line number Diff line change 1
1
package lru
2
2
3
3
import (
4
- "crypto/rand"
5
- "math"
6
- "math/big"
7
4
"testing"
8
5
)
9
6
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
-
18
7
func Benchmark2Q_Rand (b * testing.B ) {
19
8
l , err := New2Q (8192 )
20
9
if err != nil {
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ func BenchmarkARC_Rand(b *testing.B) {
18
18
19
19
trace := make ([]int64 , b .N * 2 )
20
20
for i := 0 ; i < b .N * 2 ; i ++ {
21
- trace [i ] = rand . Int63 ( ) % 32768
21
+ trace [i ] = getRand ( b ) % 32768
22
22
}
23
23
24
24
b .ResetTimer ()
@@ -48,9 +48,9 @@ func BenchmarkARC_Freq(b *testing.B) {
48
48
trace := make ([]int64 , b .N * 2 )
49
49
for i := 0 ; i < b .N * 2 ; i ++ {
50
50
if i % 2 == 0 {
51
- trace [i ] = rand . Int63 ( ) % 16384
51
+ trace [i ] = getRand ( b ) % 16384
52
52
} else {
53
- trace [i ] = rand . Int63 ( ) % 32768
53
+ trace [i ] = getRand ( b ) % 32768
54
54
}
55
55
}
56
56
@@ -80,8 +80,8 @@ func TestARC_RandomOps(t *testing.T) {
80
80
81
81
n := 200000
82
82
for i := 0 ; i < n ; i ++ {
83
- key := rand . Int63 ( ) % 512
84
- r := rand . Int63 ( )
83
+ key := getRand ( t ) % 512
84
+ r := getRand ( t )
85
85
switch r % 3 {
86
86
case 0 :
87
87
l .Add (key , key )
Original file line number Diff line number Diff line change 1
1
package lru
2
2
3
3
import (
4
- "math/rand"
5
4
"testing"
6
5
)
7
6
@@ -13,7 +12,7 @@ func BenchmarkLRU_Rand(b *testing.B) {
13
12
14
13
trace := make ([]int64 , b .N * 2 )
15
14
for i := 0 ; i < b .N * 2 ; i ++ {
16
- trace [i ] = rand . Int63 ( ) % 32768
15
+ trace [i ] = getRand ( b ) % 32768
17
16
}
18
17
19
18
b .ResetTimer ()
@@ -43,9 +42,9 @@ func BenchmarkLRU_Freq(b *testing.B) {
43
42
trace := make ([]int64 , b .N * 2 )
44
43
for i := 0 ; i < b .N * 2 ; i ++ {
45
44
if i % 2 == 0 {
46
- trace [i ] = rand . Int63 ( ) % 16384
45
+ trace [i ] = getRand ( b ) % 16384
47
46
} else {
48
- trace [i ] = rand . Int63 ( ) % 32768
47
+ trace [i ] = getRand ( b ) % 32768
49
48
}
50
49
}
51
50
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