MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / BenchmarkPutAndOverflow

Function BenchmarkPutAndOverflow

auth/password_hash_test.go:262–318  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

260}
261
262func BenchmarkPutAndOverflow(b *testing.B) {
263 const maxCacheSize = 100
264
265 setupCache := func(cacheType cacheType, warmupCache bool) (cache Cache) {
266 if cacheType == randReplKeyCache {
267 cache = NewRandReplKeyCache(maxCacheSize)
268 } else if cacheType == noReplKeyCache {
269 cache = NewNoReplKeyCache(maxCacheSize)
270 }
271 if warmupCache {
272 for i := 0; i < maxCacheSize; i++ {
273 cache.Put(randKey(math.MaxUint32))
274 }
275 }
276 return cache
277 }
278
279 benchmarks := []struct {
280 name string
281 cacheType cacheType
282 warmupCache bool
283 runParallel bool
284 }{
285 {"FillRandReplKeyCache", randReplKeyCache, false, false},
286 {"FillNoReplKeyCache", noReplKeyCache, false, false},
287
288 {"RefillRandReplKeyCache", randReplKeyCache, true, false},
289 {"RefillNoReplKeyCache", noReplKeyCache, true, false},
290
291 {"ParallelFillRandReplKeyCache", randReplKeyCache, false, true},
292 {"ParallelFillNoReplKeyCache", noReplKeyCache, false, true},
293
294 {"ParallelRefillRandReplKeyCache", randReplKeyCache, true, true},
295 {"ParallelRefillNoReplKeyCache", noReplKeyCache, true, true},
296 }
297 for _, bm := range benchmarks {
298 b.Run(bm.name, func(b *testing.B) {
299 cache := setupCache(bm.cacheType, bm.warmupCache)
300 b.ResetTimer()
301 if bm.runParallel {
302 b.RunParallel(func(pb *testing.PB) {
303 b.ReportAllocs()
304 for pb.Next() {
305 cache.Put(randKey(math.MaxUint32))
306 }
307 })
308 } else {
309 b.Run(bm.name, func(b *testing.B) {
310 b.ReportAllocs()
311 for i := 0; i < b.N; i++ {
312 cache.Put(randKey(math.MaxUint32))
313 }
314 })
315 }
316 })
317 }
318}
319

Callers

nothing calls this directly

Calls 6

NewRandReplKeyCacheFunction · 0.85
NewNoReplKeyCacheFunction · 0.85
randKeyFunction · 0.85
PutMethod · 0.65
RunMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected