MCPcopy Index your code
hub / github.com/patrickmn/go-cache / benchmarkCacheGetManyConcurrent

Function benchmarkCacheGetManyConcurrent

cache_test.go:1549–1575  ·  view source on GitHub ↗
(b *testing.B, exp time.Duration)

Source from the content-addressed store, hash-verified

1547}
1548
1549func benchmarkCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
1550 // This is the same as BenchmarkCacheGetConcurrent, but its result
1551 // can be compared against BenchmarkShardedCacheGetManyConcurrent
1552 // in sharded_test.go.
1553 b.StopTimer()
1554 n := 10000
1555 tc := New(exp, 0)
1556 keys := make([]string, n)
1557 for i := 0; i < n; i++ {
1558 k := "foo" + strconv.Itoa(n)
1559 keys[i] = k
1560 tc.Set(k, "bar", DefaultExpiration)
1561 }
1562 each := b.N / n
1563 wg := new(sync.WaitGroup)
1564 wg.Add(n)
1565 for _, v := range keys {
1566 go func() {
1567 for j := 0; j < each; j++ {
1568 tc.Get(v)
1569 }
1570 wg.Done()
1571 }()
1572 }
1573 b.StartTimer()
1574 wg.Wait()
1575}
1576
1577func BenchmarkCacheSetExpiring(b *testing.B) {
1578 benchmarkCacheSet(b, 5*time.Minute)

Calls 4

NewFunction · 0.85
SetMethod · 0.45
AddMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…