MCPcopy Create free account
hub / github.com/patrickmn/go-cache / BenchmarkRWMutexMapGetConcurrent

Function BenchmarkRWMutexMapGetConcurrent

cache_test.go:1517–1539  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1515}
1516
1517func BenchmarkRWMutexMapGetConcurrent(b *testing.B) {
1518 b.StopTimer()
1519 m := map[string]string{
1520 "foo": "bar",
1521 }
1522 mu := sync.RWMutex{}
1523 wg := new(sync.WaitGroup)
1524 workers := runtime.NumCPU()
1525 each := b.N / workers
1526 wg.Add(workers)
1527 b.StartTimer()
1528 for i := 0; i < workers; i++ {
1529 go func() {
1530 for j := 0; j < each; j++ {
1531 mu.RLock()
1532 _, _ = m["foo"]
1533 mu.RUnlock()
1534 }
1535 wg.Done()
1536 }()
1537 }
1538 wg.Wait()
1539}
1540
1541func BenchmarkCacheGetManyConcurrentExpiring(b *testing.B) {
1542 benchmarkCacheGetManyConcurrent(b, 5*time.Minute)

Callers

nothing calls this directly

Calls 1

AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…