Showing content from http://mail.python.org/pipermail/python-dev/attachments/20151018/155a9ee4/attachment.html below:
<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 October 2015 at 17:41, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank" class="cremed">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Oct 19, 2015 at 11:35 AM, David Mertz <<a href="mailto:mertz@gnosis.cx" class="cremed">mertz@gnosis.cx</a>> wrote:<br>
> That's interesting about the `self._full` variable slowing it down, I think<br>
> I'm not surprised (but obviously it depends on just how it's used). But one<br>
> can also simply define RingBuffer.isfull() using `self.max==len(self.data)`<br>
> if you prefer that approach. I doubt `myringbuffer.isfull()` is something<br>
> you need to call in an inner loop.<br>
><br>
> That said, I think my implementation of RingBuffer would probably look more<br>
> like (completely untested):<br>
><br>
> class RingBuffer(object):<br>
>Â Â Â def __init__(self, size_max):<br>
>Â Â Â Â Â self.data = [None] * size_max<br>
>Â Â Â Â Â self.size_max = size_max<br>
>Â Â Â Â Â self.used = 0<br>
>Â Â Â Â Â self.cur = 0<br>
>Â Â Â def append(self, val):<br>
>Â Â Â Â Â self.data[self.cur] = val<br>
>Â Â Â Â Â self.cur = (self.cur+1) % self.size_max<br>
>Â Â Â Â Â self.used = max(self.used, self.cur+1)<br>
>Â Â Â def isfull(self):<br>
>Â Â Â Â Â self.used == self.size_max<br>
><br>
> Feel free to try this version against whatever benchmark you have in mind.<br>
<br>
</span>What does this provide that collections.deque(maxlen=size_max)<br>
doesn't? I'm a little lost.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:verdana,sans-serif">âI was merely re-implementing the "clever" code in a slightly less clever way, for the same performance, to demonstrate that there's no need to assign to __class__.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">collections.deque is about 5x faster.</div><div class="gmail_default" style="font-family:verdana,sans-serif">(My simple benchmark tests the cost of x.append(i))</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">- pâ</div><br></div><div>Â </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
ChrisA<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" class="cremed">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank" class="cremed">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/pludemann%40google.com" rel="noreferrer" target="_blank" class="cremed">https://mail.python.org/mailman/options/python-dev/pludemann%40google.com</a><br>
</div></div></blockquote></div><br></div></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4