Skip to content

Commit c71c794

Browse files
committed
test: add comprehensive benchmarks for queue operations
- Add benchmark tests for ring queue operations - Add parallel queue and request benchmarks - Add concurrent queue benchmarks - Add ring resize operation benchmarks Signed-off-by: appleboy <[email protected]>
1 parent 603cfe4 commit c71c794

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

ring_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,45 @@ func TestErrNoTaskInQueue(t *testing.T) {
508508
assert.Error(t, err)
509509
assert.Equal(t, ErrNoTaskInQueue, err)
510510
}
511+
512+
func BenchmarkRingQueue(b *testing.B) {
513+
b.Run("queue and request operations", func(b *testing.B) {
514+
w := NewRing(WithQueueSize(1000))
515+
m := mockMessage{message: "test"}
516+
517+
b.ResetTimer()
518+
b.RunParallel(func(pb *testing.PB) {
519+
for pb.Next() {
520+
_ = w.Queue(&m)
521+
_, _ = w.Request()
522+
}
523+
})
524+
})
525+
526+
b.Run("concurrent queue operations", func(b *testing.B) {
527+
w := NewRing(WithQueueSize(1000))
528+
m := mockMessage{message: "test"}
529+
530+
b.ResetTimer()
531+
b.RunParallel(func(pb *testing.PB) {
532+
for pb.Next() {
533+
_ = w.Queue(&m)
534+
}
535+
})
536+
})
537+
538+
b.Run("resize operations", func(b *testing.B) {
539+
w := NewRing()
540+
m := mockMessage{message: "test"}
541+
542+
b.ResetTimer()
543+
for i := 0; i < b.N; i++ {
544+
for j := 0; j < 100; j++ {
545+
_ = w.Queue(&m)
546+
}
547+
for j := 0; j < 100; j++ {
548+
_, _ = w.Request()
549+
}
550+
}
551+
})
552+
}

0 commit comments

Comments
 (0)