MCPcopy
hub / github.com/redis/go-redis / BenchmarkWantConnQueue_Dequeue

Function BenchmarkWantConnQueue_Dequeue

internal/pool/want_conn_test.go:398–430  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

396}
397
398func BenchmarkWantConnQueue_Dequeue(b *testing.B) {
399 q := newWantConnQueue()
400
401 // Use a reasonable fixed size for pre-population to avoid memory issues
402 const queueSize = 10000
403
404 // Pre-populate queue with a fixed reasonable size
405 for i := 0; i < queueSize; i++ {
406 w := &wantConn{
407 ctx: context.Background(),
408 result: make(chan wantConnResult, 1),
409 }
410 q.enqueue(w)
411 }
412
413 b.ResetTimer()
414
415 // Benchmark dequeue operations, refilling as needed
416 for i := 0; i < b.N; i++ {
417 if _, ok := q.dequeue(); !ok {
418 // Queue is empty, refill a batch
419 for j := 0; j < 1000; j++ {
420 w := &wantConn{
421 ctx: context.Background(),
422 result: make(chan wantConnResult, 1),
423 }
424 q.enqueue(w)
425 }
426 // Dequeue again
427 q.dequeue()
428 }
429 }
430}
431
432func BenchmarkWantConnQueue_EnqueueDequeue(b *testing.B) {
433 q := newWantConnQueue()

Callers

nothing calls this directly

Calls 3

newWantConnQueueFunction · 0.85
enqueueMethod · 0.80
dequeueMethod · 0.80

Tested by

no test coverage detected