sm
/
cache
1
0
Fork 0

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