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

Function benchmarkCacheGetConcurrent

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

Source from the content-addressed store, hash-verified

1495}
1496
1497func benchmarkCacheGetConcurrent(b *testing.B, exp time.Duration) {
1498 b.StopTimer()
1499 tc := New(exp, 0)
1500 tc.Set("foo", "bar", DefaultExpiration)
1501 wg := new(sync.WaitGroup)
1502 workers := runtime.NumCPU()
1503 each := b.N / workers
1504 wg.Add(workers)
1505 b.StartTimer()
1506 for i := 0; i < workers; i++ {
1507 go func() {
1508 for j := 0; j < each; j++ {
1509 tc.Get("foo")
1510 }
1511 wg.Done()
1512 }()
1513 }
1514 wg.Wait()
1515}
1516
1517func BenchmarkRWMutexMapGetConcurrent(b *testing.B) {
1518 b.StopTimer()

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…