Skip to content

Commit 9fc6f9c

Browse files
committed
Add expiring/notexpiring sharded cache benchmarks
1 parent afadf13 commit 9fc6f9c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

sharded_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"strconv"
55
"sync"
66
"testing"
7+
"time"
78
)
89

910
// func TestDjb33(t *testing.T) {
@@ -32,20 +33,36 @@ func TestShardedCache(t *testing.T) {
3233
}
3334
}
3435

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) {
3645
b.StopTimer()
37-
tc := unexportedNewSharded(DefaultExpiration, 0, 10)
46+
tc := unexportedNewSharded(exp, 0, 10)
3847
tc.Set("foobarba", "zquux", DefaultExpiration)
3948
b.StartTimer()
4049
for i := 0; i < b.N; i++ {
4150
tc.Get("foobarba")
4251
}
4352
}
4453

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) {
4663
b.StopTimer()
4764
n := 10000
48-
tsc := unexportedNewSharded(DefaultExpiration, 0, 20)
65+
tsc := unexportedNewSharded(exp, 0, 20)
4966
keys := make([]string, n)
5067
for i := 0; i < n; i++ {
5168
k := "foo" + strconv.Itoa(n)

0 commit comments

Comments
 (0)