File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -508,3 +508,45 @@ func TestErrNoTaskInQueue(t *testing.T) {
508
508
assert .Error (t , err )
509
509
assert .Equal (t , ErrNoTaskInQueue , err )
510
510
}
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
+ }
You can’t perform that action at this time.
0 commit comments