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

Function benchmarkShardedCacheGetManyConcurrent

sharded_test.go:62–85  ·  view source on GitHub ↗
(b *testing.B, exp time.Duration)

Source from the content-addressed store, hash-verified

60}
61
62func benchmarkShardedCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
63 b.StopTimer()
64 n := 10000
65 tsc := unexportedNewSharded(exp, 0, 20)
66 keys := make([]string, n)
67 for i := 0; i < n; i++ {
68 k := "foo" + strconv.Itoa(n)
69 keys[i] = k
70 tsc.Set(k, "bar", DefaultExpiration)
71 }
72 each := b.N / n
73 wg := new(sync.WaitGroup)
74 wg.Add(n)
75 for _, v := range keys {
76 go func() {
77 for j := 0; j < each; j++ {
78 tsc.Get(v)
79 }
80 wg.Done()
81 }()
82 }
83 b.StartTimer()
84 wg.Wait()
85}

Calls 4

unexportedNewShardedFunction · 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…