Add GetManyConcurrent benchmarks for LRU cache
This commit is contained in:
parent
6a67eef9fd
commit
cd479c6eeb
|
@ -1539,17 +1539,17 @@ func BenchmarkRWMutexInterfaceMapGetString(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCacheWithLRUGetConcurrentExpiring(b *testing.B) {
|
func BenchmarkCacheGetConcurrentExpiring(b *testing.B) {
|
||||||
benchmarkCacheWithLRUGetConcurrent(b, 5*time.Minute, 10)
|
benchmarkCacheGetConcurrent(b, 5*time.Minute)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCacheWithLRUGetConcurrentNotExpiring(b *testing.B) {
|
func BenchmarkCacheGetConcurrentNotExpiring(b *testing.B) {
|
||||||
benchmarkCacheWithLRUGetConcurrent(b, NoExpiration, 10)
|
benchmarkCacheGetConcurrent(b, NoExpiration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkCacheWithLRUGetConcurrent(b *testing.B, exp time.Duration, max int) {
|
func benchmarkCacheGetConcurrent(b *testing.B, exp time.Duration) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
tc := NewWithLRU(exp, 0, max)
|
tc := New(exp, 0)
|
||||||
tc.Set("foo", "bar", DefaultExpiration)
|
tc.Set("foo", "bar", DefaultExpiration)
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
workers := runtime.NumCPU()
|
workers := runtime.NumCPU()
|
||||||
|
@ -1567,17 +1567,17 @@ func benchmarkCacheWithLRUGetConcurrent(b *testing.B, exp time.Duration, max int
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCacheGetConcurrentExpiring(b *testing.B) {
|
func BenchmarkCacheWithLRUGetConcurrentExpiring(b *testing.B) {
|
||||||
benchmarkCacheGetConcurrent(b, 5*time.Minute)
|
benchmarkCacheWithLRUGetConcurrent(b, 5*time.Minute, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCacheGetConcurrentNotExpiring(b *testing.B) {
|
func BenchmarkCacheWithLRUGetConcurrentNotExpiring(b *testing.B) {
|
||||||
benchmarkCacheGetConcurrent(b, NoExpiration)
|
benchmarkCacheWithLRUGetConcurrent(b, NoExpiration, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkCacheGetConcurrent(b *testing.B, exp time.Duration) {
|
func benchmarkCacheWithLRUGetConcurrent(b *testing.B, exp time.Duration, max int) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
tc := New(exp, 0)
|
tc := NewWithLRU(exp, 0, max)
|
||||||
tc.Set("foo", "bar", DefaultExpiration)
|
tc.Set("foo", "bar", DefaultExpiration)
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
workers := runtime.NumCPU()
|
workers := runtime.NumCPU()
|
||||||
|
@ -1655,6 +1655,42 @@ func benchmarkCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkCacheWithLRUGetManyConcurrentExpiring(b *testing.B) {
|
||||||
|
benchmarkCacheWithLRUGetManyConcurrent(b, 5*time.Minute, 10000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkCacheWithLRUGetManyConcurrentNotExpiring(b *testing.B) {
|
||||||
|
benchmarkCacheWithLRUGetManyConcurrent(b, NoExpiration, 10000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkCacheWithLRUGetManyConcurrent(b *testing.B, exp time.Duration, max int) {
|
||||||
|
// This is the same as BenchmarkCacheWithLRUGetConcurrent, but its result
|
||||||
|
// can be compared against BenchmarkShardedCacheWithLRUGetManyConcurrent
|
||||||
|
// in sharded_test.go.
|
||||||
|
b.StopTimer()
|
||||||
|
n := 10000
|
||||||
|
tc := NewWithLRU(exp, 0, max)
|
||||||
|
keys := make([]string, n)
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
k := "foo" + strconv.Itoa(n)
|
||||||
|
keys[i] = k
|
||||||
|
tc.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++ {
|
||||||
|
tc.Get(v)
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
b.StartTimer()
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkCacheSetExpiring(b *testing.B) {
|
func BenchmarkCacheSetExpiring(b *testing.B) {
|
||||||
benchmarkCacheSet(b, 5*time.Minute)
|
benchmarkCacheSet(b, 5*time.Minute)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue