Use operator.index to avoid DeprecationWarning on Python 2
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
Showing
Please register or sign in to comment