Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use an RWMutex in the cache-equivalent map tests now that the cache u…

…ses one
  • Loading branch information...
commit 155ab21e5d909bb06709e3112783cfd459e6de50 1 parent 3986bff
@pmylund authored
Showing with 6 additions and 6 deletions.
  1. +6 −6 cache_test.go
View
12 cache_test.go
@@ -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()
}()
Please sign in to comment.
Something went wrong with that request. Please try again.