Code

Three ways to take from the front

Create queue.go (see the panel). It holds History (the stack), three queue strategies and Ring.

heapKB runs the garbage collector and reports what is still alive in memory. Why that is needed becomes clear in a moment.

The result

$ algo queue -n 100000
enqueue 100000 items, then dequeue every one

strategy                   elements moved
q = q[1:]                               0
copy-down                      4999950000
ring buffer                             0

Compare that with your guess.

q = q[1:] moves zero elements. Not few — zero. A slice header is a pointer, a len and a cap; moving it forward means adding one element to the pointer and decrementing len. The data does not go anywhere.

copy-down moves five billion. Exactly 4,999,950,000. Every removal shifts everything still queued, so the total is n(n−1)/2. Grow n by ten and the number grows by a hundred:

n shifts
1,000 499,500
10,000 49,995,000
100,000 4,999,950,000

That is O(n²), and it happened because of one innocent-looking line.

So option A won?

According to the counter, yes. A and C tie, and both annihilate B.

The counter is wrong. More precisely — the counter answered a question we did not think to ask.