• Jason Madden's avatar
    Use operator.index to avoid DeprecationWarning on Python 2 · 4debe1bb
    Jason Madden authored
    Fixes #79
    
    Slightly faster on CPython:
    
    $ python -m perf timeit -s 'from struct import Struct; s = Struct("i"); unpack=s.unpack; pack=s.pack' 'unpack(pack(123456))'
    .....................
    Mean +- std dev: 252 ns +- 12 ns
    $ python -m perf timeit -s 'from struct import Struct; s = Struct("i"); from operator import index; pack=s.pack' 'pack(index(123456))'
    .....................
    Mean +- std dev: 235 ns +- 6 ns
    
    Very slightly faster on PyPy:
    
    python -m perf timeit -s 'from struct import Struct; s = Struct("i"); unpack=s.unpack; pack=s.pack' 'unpack(pack(123456))'
    .........
    Mean +- std dev: 4.24 ns +- 0.12 ns
    $ python -m perf timeit -s 'from struct import Struct; s = Struct("i"); from operator import index; pack=s.pack' 'pack(index(123456))'
    .........
    Mean +- std dev: 4.19 ns +- 0.10 ns
    4debe1bb
To find the state of this project's repository at the time of any of these versions, check out the tags.
CHANGES.rst 8.18 KB