From 8c41258ef3755975cf45e9a1dcde8586a6656cd7 Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Thu, 3 Dec 2015 09:40:14 -0500 Subject: [PATCH 1/2] Add BenchmarkRWMutexInterfaceMapGet --- cache_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cache_test.go b/cache_test.go index 5a3b396..e30adc7 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1457,6 +1457,21 @@ func BenchmarkRWMutexMapGet(b *testing.B) { } } +func BenchmarkRWMutexInterfaceMapGet(b *testing.B) { + b.StopTimer() + s := struct{name string}{name: "foo"} + m := map[interface{}]string{ + s: "bar", + } + mu := sync.RWMutex{} + b.StartTimer() + for i := 0; i < b.N; i++ { + mu.RLock() + _, _ = m[s] + mu.RUnlock() + } +} + func BenchmarkCacheGetConcurrentExpiring(b *testing.B) { benchmarkCacheGetConcurrent(b, 5*time.Minute) } From 721cc9438c91df8997d39584a6740e2aba3100a7 Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Thu, 3 Dec 2015 09:55:58 -0500 Subject: [PATCH 2/2] Add BenchmarkRWMutexInterfaceMapGetString --- cache_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cache_test.go b/cache_test.go index e30adc7..6e81693 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1457,7 +1457,7 @@ func BenchmarkRWMutexMapGet(b *testing.B) { } } -func BenchmarkRWMutexInterfaceMapGet(b *testing.B) { +func BenchmarkRWMutexInterfaceMapGetStruct(b *testing.B) { b.StopTimer() s := struct{name string}{name: "foo"} m := map[interface{}]string{ @@ -1472,6 +1472,20 @@ func BenchmarkRWMutexInterfaceMapGet(b *testing.B) { } } +func BenchmarkRWMutexInterfaceMapGetString(b *testing.B) { + b.StopTimer() + m := map[interface{}]string{ + "foo": "bar", + } + mu := sync.RWMutex{} + b.StartTimer() + for i := 0; i < b.N; i++ { + mu.RLock() + _, _ = m["foo"] + mu.RUnlock() + } +} + func BenchmarkCacheGetConcurrentExpiring(b *testing.B) { benchmarkCacheGetConcurrent(b, 5*time.Minute) }