|
|
@ -3,6 +3,7 @@ package cache
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"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) {
|
|
|
|
func BenchmarkMapGet(b *testing.B) {
|
|
|
|
m := map[string]string{
|
|
|
|
m := map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"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) {
|
|
|
|
func BenchmarkCacheSet(b *testing.B) {
|
|
|
|
tc := New(0, 0)
|
|
|
|
tc := New(0, 0)
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|