BenchmarkCircularQueue benchmarks the CircularQueue implementation.
(b *testing.B)
| 226 | |
| 227 | // BenchmarkCircularQueue benchmarks the CircularQueue implementation. |
| 228 | func BenchmarkCircularQueue(b *testing.B) { |
| 229 | b.Run("Enqueue", func(b *testing.B) { |
| 230 | queue, _ := NewCircularQueue[int](1000) |
| 231 | for i := 0; i < b.N; i++ { |
| 232 | if err := queue.Enqueue(i); err != nil { |
| 233 | b.Error(err) |
| 234 | } |
| 235 | } |
| 236 | }) |
| 237 | |
| 238 | b.Run("Dequeue", func(b *testing.B) { |
| 239 | queue, _ := NewCircularQueue[int](1000) |
| 240 | for i := 0; i < 1000; i++ { |
| 241 | if err := queue.Enqueue(i); err != nil { |
| 242 | b.Error(err) |
| 243 | } |
| 244 | } |
| 245 | b.ResetTimer() |
| 246 | for i := 0; i < b.N; i++ { |
| 247 | if _, err := queue.Dequeue(); err != nil { |
| 248 | b.Error(err) |
| 249 | } |
| 250 | } |
| 251 | }) |
| 252 | |
| 253 | b.Run("Peek", func(b *testing.B) { |
| 254 | queue, _ := NewCircularQueue[int](1000) |
| 255 | for i := 0; i < 1000; i++ { |
| 256 | if err := queue.Enqueue(i); err != nil { |
| 257 | b.Error(err) |
| 258 | } |
| 259 | } |
| 260 | b.ResetTimer() |
| 261 | for i := 0; i < b.N; i++ { |
| 262 | if _, err := queue.Peek(); err != nil { |
| 263 | b.Error(err) |
| 264 | } |
| 265 | } |
| 266 | }) |
| 267 | } |