MCPcopy Create free account
hub / github.com/antchfx/xpath / BenchmarkLoadingCacheNoCap_MultiThread

Function BenchmarkLoadingCacheNoCap_MultiThread

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

Source from the content-addressed store, hash-verified

134}
135
136func BenchmarkLoadingCacheNoCap_MultiThread(b *testing.B) {
137 rand.Seed(benchLoadingCacheRandSeed)
138 c := NewLoadingCache(
139 func(key interface{}) (interface{}, error) {
140 return key, nil
141 }, 0) // 0 => no cap
142 errCh := make(chan error, benchLoadingCacheConcurrency)
143 defer close(errCh)
144 for i := 0; i < benchLoadingCacheConcurrency; i++ {
145 go func() {
146 for j := 0; j < b.N; j++ {
147 k := rand.Intn(benchLoadingCacheKeyRange)
148 v, _ := c.get(k)
149 if k != v {
150 errCh <- fmt.Errorf("key:%q != value:%q", k, v)
151 return
152 }
153 }
154 errCh <- nil
155 return
156 }()
157 }
158 for i := 0; i < benchLoadingCacheConcurrency; i++ {
159 if err := <-errCh; err != nil {
160 b.Fatal(err)
161 }
162 }
163 b.Logf("N=%d, concurrency=%d, reset=%d", b.N, benchLoadingCacheConcurrency, c.reset)
164}
165
166func TestGetRegexp(t *testing.T) {
167 RegexpCache = defaultRegexpCache()

Callers

nothing calls this directly

Calls 2

NewLoadingCacheFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…