|
4 | 4 | "strconv"
|
5 | 5 | "sync"
|
6 | 6 | "testing"
|
| 7 | + "time" |
7 | 8 | )
|
8 | 9 |
|
9 | 10 | // func TestDjb33(t *testing.T) {
|
@@ -32,20 +33,36 @@ func TestShardedCache(t *testing.T) {
|
32 | 33 | }
|
33 | 34 | }
|
34 | 35 |
|
35 |
| -func BenchmarkShardedCacheGet(b *testing.B) { |
| 36 | +func BenchmarkShardedCacheGetExpiring(b *testing.B) { |
| 37 | + benchmarkShardedCacheGet(b, 5 * time.Minute) |
| 38 | +} |
| 39 | + |
| 40 | +func BenchmarkShardedCacheGetNotExpiring(b *testing.B) { |
| 41 | + benchmarkShardedCacheGet(b, NoExpiration) |
| 42 | +} |
| 43 | + |
| 44 | +func benchmarkShardedCacheGet(b *testing.B, exp time.Duration) { |
36 | 45 | b.StopTimer()
|
37 |
| - tc := unexportedNewSharded(DefaultExpiration, 0, 10) |
| 46 | + tc := unexportedNewSharded(exp, 0, 10) |
38 | 47 | tc.Set("foobarba", "zquux", DefaultExpiration)
|
39 | 48 | b.StartTimer()
|
40 | 49 | for i := 0; i < b.N; i++ {
|
41 | 50 | tc.Get("foobarba")
|
42 | 51 | }
|
43 | 52 | }
|
44 | 53 |
|
45 |
| -func BenchmarkShardedCacheGetManyConcurrent(b *testing.B) { |
| 54 | +func BenchmarkShardedCacheGetManyConcurrentExpiring(b *testing.B) { |
| 55 | + benchmarkShardedCacheGetManyConcurrent(b, 5 * time.Minute) |
| 56 | +} |
| 57 | + |
| 58 | +func BenchmarkShardedCacheGetManyConcurrentNotExpiring(b *testing.B) { |
| 59 | + benchmarkShardedCacheGetManyConcurrent(b, NoExpiration) |
| 60 | +} |
| 61 | + |
| 62 | +func benchmarkShardedCacheGetManyConcurrent(b *testing.B, exp time.Duration) { |
46 | 63 | b.StopTimer()
|
47 | 64 | n := 10000
|
48 |
| - tsc := unexportedNewSharded(DefaultExpiration, 0, 20) |
| 65 | + tsc := unexportedNewSharded(exp, 0, 20) |
49 | 66 | keys := make([]string, n)
|
50 | 67 | for i := 0; i < n; i++ {
|
51 | 68 | k := "foo" + strconv.Itoa(n)
|
|
0 commit comments