MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / BenchmarkCircularQueue

Function BenchmarkCircularQueue

structure/circularqueue/circularqueue_test.go:228–267  ·  view source on GitHub ↗

BenchmarkCircularQueue benchmarks the CircularQueue implementation.

(b *testing.B)

Source from the content-addressed store, hash-verified

226
227// BenchmarkCircularQueue benchmarks the CircularQueue implementation.
228func 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}

Callers

nothing calls this directly

Calls 3

EnqueueMethod · 0.45
DequeueMethod · 0.45
PeekMethod · 0.45

Tested by

no test coverage detected