From 9fc6f9c73f5599519846febf41781f43e2b9efca Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Mon, 30 Nov 2015 16:04:49 -0500 Subject: [PATCH] Add expiring/notexpiring sharded cache benchmarks --- sharded_test.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sharded_test.go b/sharded_test.go index 6ef5eb3..51088d9 100644 --- a/sharded_test.go +++ b/sharded_test.go @@ -4,6 +4,7 @@ import ( "strconv" "sync" "testing" + "time" ) // func TestDjb33(t *testing.T) { @@ -32,9 +33,17 @@ func TestShardedCache(t *testing.T) { } } -func BenchmarkShardedCacheGet(b *testing.B) { +func BenchmarkShardedCacheGetExpiring(b *testing.B) { + benchmarkShardedCacheGet(b, 5 * time.Minute) +} + +func BenchmarkShardedCacheGetNotExpiring(b *testing.B) { + benchmarkShardedCacheGet(b, NoExpiration) +} + +func benchmarkShardedCacheGet(b *testing.B, exp time.Duration) { b.StopTimer() - tc := unexportedNewSharded(DefaultExpiration, 0, 10) + tc := unexportedNewSharded(exp, 0, 10) tc.Set("foobarba", "zquux", DefaultExpiration) b.StartTimer() for i := 0; i < b.N; i++ { @@ -42,10 +51,18 @@ func BenchmarkShardedCacheGet(b *testing.B) { } } -func BenchmarkShardedCacheGetManyConcurrent(b *testing.B) { +func BenchmarkShardedCacheGetManyConcurrentExpiring(b *testing.B) { + benchmarkShardedCacheGetManyConcurrent(b, 5 * time.Minute) +} + +func BenchmarkShardedCacheGetManyConcurrentNotExpiring(b *testing.B) { + benchmarkShardedCacheGetManyConcurrent(b, NoExpiration) +} + +func benchmarkShardedCacheGetManyConcurrent(b *testing.B, exp time.Duration) { b.StopTimer() n := 10000 - tsc := unexportedNewSharded(DefaultExpiration, 0, 20) + tsc := unexportedNewSharded(exp, 0, 20) keys := make([]string, n) for i := 0; i < n; i++ { k := "foo" + strconv.Itoa(n)