Why custom ringbuffer used instead of deque?
See original GitHub issuehttps://github.com/matthiasplappert/keras-rl/blob/d9e3b64a20f056030c02bfe217085b7e54098e48/rl/memory.py#L42 states: Do not use deque to implement the memory. This data structure may seem convenient but it is way too slow on random access. Instead, we use our own ring buffer implementation.
Not sure why this is stated. I ran this quick test: ` ring = RingBuffer(maxlen = 1000)
start_time = time.time()
for i in range(100000):
ring.append(i)
print("--- %s seconds ---" % (time.time() - start_time))
d = deque(maxlen=1000)
start_time = time.time()
for i in range(100000):
d.append(i)
print("--- %s seconds ---" % (time.time() - start_time))
start_time = time.time()
for i in range(100000):
l = ring[i%1000-1]
print("--- %s seconds ---" % (time.time() - start_time))
start_time = time.time()
for i in range(100000):
l = d[i%1000]
print("--- %s seconds ---" % (time.time() - start_time))
and got this result:
— 0.0608789920807 seconds —
— 0.00712609291077 seconds —
— 0.0430929660797 seconds —
— 0.00617289543152 seconds —
`
You can see that the custom ringbuffer is significantly slower than the deque at adding or removing. Can someone explain to me what the comment is referring to exactly and why the ringbuffer is used?
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (4 by maintainers)
Top Results From Across the Web
What's the difference between a deque and circular buffer?
a fixed sized deque that serves as a memory can have its oldest value replaced (although we an remove new values). a circular...
Read more >Creating a Circular Buffer in C and C++ - Embedded Artistry
Circular buffers are often used as fixed-sized queues. The fixed size is beneficial for embedded systems, as developers often try to use static ......
Read more >c++ - Ring Buffer Implementation in C++14
A ring buffer or circular buffer is a fixed sized queue that advances head and tail pointers in a modulo manner rather than...
Read more >Performance of a Circular Buffer vs. Vector, Deque, and List
Queues are important, frequently used data structures. A queue is a container for data. It has two ends, labeled the front and back....
Read more >Optimizing a copy-on-write double-ended queue in Swift
Instead, I'll focus on the challenges involved in implementing a ... There is an existing, commonly used Deque implementation which appears ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All my changes are here: https://github.com/kirkscheper/keras-rl/tree/recurrent-ddpg
I have been playing around with lots of different things that are probably not directly ready for a pull request.
Cool, feel free to update the code to use
deque
. I’m not sure anymore why I thoughtdeque
was too slow but it seems like this was clearly not true.