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

Function BenchmarkRWMutexMapGetConcurrent

pkg/util/cache/cache_test.go:1533–1555  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1531}
1532
1533func BenchmarkRWMutexMapGetConcurrent(b *testing.B) {
1534 b.StopTimer()
1535 m := map[string]string{
1536 "foo": "bar",
1537 }
1538 mu := sync.RWMutex{}
1539 wg := new(sync.WaitGroup)
1540 workers := runtime.NumCPU()
1541 each := b.N / workers
1542 wg.Add(workers)
1543 b.StartTimer()
1544 for i := 0; i < workers; i++ {
1545 go func() {
1546 for j := 0; j < each; j++ {
1547 mu.RLock()
1548 _, _ = m["foo"]
1549 mu.RUnlock()
1550 }
1551 wg.Done()
1552 }()
1553 }
1554 wg.Wait()
1555}
1556
1557func BenchmarkCacheGetManyConcurrentExpiring(b *testing.B) {
1558 benchmarkCacheGetManyConcurrent(b, 5*time.Minute)

Callers

nothing calls this directly

Calls 3

DoneMethod · 0.80
WaitMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected