Use an RWMutex in the cache-equivalent map tests now that the cache uses one

This commit is contained in:
Patrick Mylund Nielsen 2013-06-30 20:31:46 -04:00
parent 3986bff69b
commit 155ab21e5d
1 changed files with 6 additions and 6 deletions

View File

@ -1389,12 +1389,12 @@ func BenchmarkMutexMapGet(b *testing.B) {
m := map[string]string{ m := map[string]string{
"foo": "bar", "foo": "bar",
} }
mu := sync.Mutex{} mu := sync.RWMutex{}
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
mu.Lock() mu.RLock()
_, _ = m["foo"] _, _ = m["foo"]
mu.Unlock() mu.RUnlock()
} }
} }
@ -1423,7 +1423,7 @@ func BenchmarkMutexMapGetConcurrent(b *testing.B) {
m := map[string]string{ m := map[string]string{
"foo": "bar", "foo": "bar",
} }
mu := sync.Mutex{} mu := sync.RWMutex{}
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
workers := runtime.NumCPU() workers := runtime.NumCPU()
each := b.N / workers each := b.N / workers
@ -1432,9 +1432,9 @@ func BenchmarkMutexMapGetConcurrent(b *testing.B) {
for i := 0; i < workers; i++ { for i := 0; i < workers; i++ {
go func() { go func() {
for j := 0; j < each; j++ { for j := 0; j < each; j++ {
mu.Lock() mu.RLock()
_, _ = m["foo"] _, _ = m["foo"]
mu.Unlock() mu.RUnlock()
} }
wg.Done() wg.Done()
}() }()