(b *testing.B)
| 396 | } |
| 397 | |
| 398 | func 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 | |
| 432 | func BenchmarkWantConnQueue_EnqueueDequeue(b *testing.B) { |
| 433 | q := newWantConnQueue() |
nothing calls this directly
no test coverage detected