Stop parsing the struct formats each time.
This makes the test runs in pure_python mode 15s faster. Microbenchmarks on CPython 2.7.14: $ python -m perf timeit -s 'from struct import pack,unpack' 'unpack("i", pack("i", 123456))' ..................... Mean +- std dev: 365 ns +- 12 ns $ python -m perf timeit -s 'from struct import Struct; s = Struct("i"); unpack=s.unpack; pack=s.pack' 'unpack(pack(123456))' ..................... Mean +- std dev: 251 ns +- 9 ns No appreciable difference on PyPy.
Showing
Please register or sign in to comment