cache: add vendor requirements: bbolt and go-cache
This commit is contained in:
parent
aec2265be0
commit
0c942199c9
51 changed files with 17452 additions and 0 deletions
85
vendor/github.com/patrickmn/go-cache/sharded_test.go
generated
vendored
Normal file
85
vendor/github.com/patrickmn/go-cache/sharded_test.go
generated
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// func TestDjb33(t *testing.T) {
|
||||
// }
|
||||
|
||||
var shardedKeys = []string{
|
||||
"f",
|
||||
"fo",
|
||||
"foo",
|
||||
"barf",
|
||||
"barfo",
|
||||
"foobar",
|
||||
"bazbarf",
|
||||
"bazbarfo",
|
||||
"bazbarfoo",
|
||||
"foobarbazq",
|
||||
"foobarbazqu",
|
||||
"foobarbazquu",
|
||||
"foobarbazquux",
|
||||
}
|
||||
|
||||
func TestShardedCache(t *testing.T) {
|
||||
tc := unexportedNewSharded(DefaultExpiration, 0, 13)
|
||||
for _, v := range shardedKeys {
|
||||
tc.Set(v, "value", DefaultExpiration)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkShardedCacheGetExpiring(b *testing.B) {
|
||||
benchmarkShardedCacheGet(b, 5*time.Minute)
|
||||
}
|
||||
|
||||
func BenchmarkShardedCacheGetNotExpiring(b *testing.B) {
|
||||
benchmarkShardedCacheGet(b, NoExpiration)
|
||||
}
|
||||
|
||||
func benchmarkShardedCacheGet(b *testing.B, exp time.Duration) {
|
||||
b.StopTimer()
|
||||
tc := unexportedNewSharded(exp, 0, 10)
|
||||
tc.Set("foobarba", "zquux", DefaultExpiration)
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
tc.Get("foobarba")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkShardedCacheGetManyConcurrentExpiring(b *testing.B) {
|
||||
benchmarkShardedCacheGetManyConcurrent(b, 5*time.Minute)
|
||||
}
|
||||
|
||||
func BenchmarkShardedCacheGetManyConcurrentNotExpiring(b *testing.B) {
|
||||
benchmarkShardedCacheGetManyConcurrent(b, NoExpiration)
|
||||
}
|
||||
|
||||
func benchmarkShardedCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
|
||||
b.StopTimer()
|
||||
n := 10000
|
||||
tsc := unexportedNewSharded(exp, 0, 20)
|
||||
keys := make([]string, n)
|
||||
for i := 0; i < n; i++ {
|
||||
k := "foo" + strconv.Itoa(n)
|
||||
keys[i] = k
|
||||
tsc.Set(k, "bar", DefaultExpiration)
|
||||
}
|
||||
each := b.N / n
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(n)
|
||||
for _, v := range keys {
|
||||
go func() {
|
||||
for j := 0; j < each; j++ {
|
||||
tsc.Get(v)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
b.StartTimer()
|
||||
wg.Wait()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue