Add test for concurrent cache.Get

This commit is contained in:
Patrick Mylund Nielsen 2012-02-21 18:46:25 +01:00
parent 8805e79189
commit 84d15102eb
1 changed files with 30 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package cache
import (
"bytes"
"io/ioutil"
"sync"
"testing"
"time"
)
@ -641,6 +642,20 @@ func BenchmarkCacheGet(b *testing.B) {
}
}
func BenchmarkCacheGetConcurrent(b *testing.B) {
tc := New(0, 0)
tc.Set("foo", "bar", 0)
wg := new(sync.WaitGroup)
wg.Add(b.N)
for i := 0; i < b.N; i++ {
go func() {
tc.Get("foo")
wg.Done()
}()
}
wg.Wait()
}
func BenchmarkMapGet(b *testing.B) {
m := map[string]string{
"foo": "bar",
@ -650,6 +665,21 @@ func BenchmarkMapGet(b *testing.B) {
}
}
// func BenchmarkMapGetConcurrent(b *testing.B) {
// m := map[string]string{
// "foo": "bar",
// }
// wg := new(sync.WaitGroup)
// wg.Add(b.N)
// for i := 0; i < b.N; i++ {
// go func() {
// _, _ = m["foo"]
// wg.Done()
// }()
// }
// wg.Wait()
// }
func BenchmarkCacheSet(b *testing.B) {
tc := New(0, 0)
for i := 0; i < b.N; i++ {