MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / benchmarkCacheGetManyConcurrent

Function benchmarkCacheGetManyConcurrent

pkg/util/cache/cache_test.go:1565–1591  ·  view source on GitHub ↗
(b *testing.B, exp time.Duration)

Source from the content-addressed store, hash-verified

1563}
1564
1565func benchmarkCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
1566 // This is the same as BenchmarkCacheGetConcurrent, but its result
1567 // can be compared against BenchmarkShardedCacheGetManyConcurrent
1568 // in sharded_test.go.
1569 b.StopTimer()
1570 n := 10000
1571 tc := New(exp, 0)
1572 keys := make([]string, n)
1573 for i := 0; i < n; i++ {
1574 k := "foo" + strconv.Itoa(n)
1575 keys[i] = k
1576 tc.Set(k, "bar", DefaultExpiration)
1577 }
1578 each := b.N / n
1579 wg := new(sync.WaitGroup)
1580 wg.Add(n)
1581 for _, v := range keys {
1582 go func() {
1583 for j := 0; j < each; j++ {
1584 tc.Get(v)
1585 }
1586 wg.Done()
1587 }()
1588 }
1589 b.StartTimer()
1590 wg.Wait()
1591}
1592
1593func BenchmarkCacheSetExpiring(b *testing.B) {
1594 benchmarkCacheSet(b, 5*time.Minute)

Calls 6

DoneMethod · 0.80
NewFunction · 0.70
SetMethod · 0.65
GetMethod · 0.65
WaitMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected