-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benefits of this library? #24
Comments
The advantage is to keep adding and removing without needing to allocate more space or move items in the slice. If you keep appending to a slice and removing items from the front, the slice will need to grow its underlying memory. In your example, Also, suppose you want to insert items to the front of the queue. This means you will need to make more room in the queue or create a new larger queue, and then move all the items one place towards the back, then add the new item at position 0. The deque avoids all that allocating and copying by using a circular buffer that keeps moving the head and tail inside the same slice as data is written and read. https://github.com/gammazero/deque/wiki#deque-diagram |
Hi, gammazero. I run a benchmark to compare the
And here is the result:
I ran it on my mackbook, with golang 1.21.0 |
And here is another benchmark to compare the golang standard
And here is the result:
It really fast than
So i think dqueue should compare with the |
Using a slice will always be faster per operation. Deque uses a slice internally, but keeps track of what elements in the slice are used and which are free for re-use. The advantage with Deque is reducing GC over time, particularly with long-running queue/dequeue activity. Benchmarks that only write to the Deque and then only read from the Deque wiil not show any advantage. This is because Deque's internal memory is never being reused, it is only filled and drained. Note: Deque now has a |
Maybe something changed, but when I rerun @woodliu benchmarks, I've got different results:
The |
What's the advantage, if any, of using this in place of standard slice?
Taken from Marwan Burelle's example on SO:
Does deque offer any benchmarks comparing it to standard slice implementations?
The text was updated successfully, but these errors were encountered: