Josh Rosenberg added the comment:

Looking at a single lookup performed over and over isn't going to get you a 
very good benchmark. If your keys are constantly reused, most of the losses 
won't show themselves. A more fair comparison I've used before is the 
difference between using the bytes object produced by bytes.maketrans as the 
mapping object for str.translate vs. using the dictionary produced by 
str.maketrans. That gets you the dynamically generated lookups that don't hit 
the dict optimizations for repeatedly looking up the same key, don't 
predictably access the same memory that never leaves the CPU cache, etc.

Check the timing data I submitted with #21118; the exact same translation 
applied to the same input strings, with the only difference being whether the 
table is bytes or dict, takes nearly twice as long using a dict as it does 
using a bytes object. And the bytes object isn't actually being used 
efficiently here; str.translate isn't optimized for the buffer protocol or 
anything, so it's constantly retrieving the cached small ints; a tuple might be 
even faster by avoiding that minor additional cost.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21911>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to