[issue29300] Modify the _struct module to use FASTCALL and Argument Clinic
STINNER Victor
report at bugs.python.org
Thu Feb 2 08:15:48 EST 2017
STINNER Victor added the comment:
Serhiy Storchaka: "But after converting the struct module to Argument Clinic struct.pack() is faster than int.to_bytes() again!"
Sorry about that ;-)
Serhiy Storchaka: "Now I need to find other ways to make int.to_bytes() even faster to win this chase."
I ran a microbenchmark:
$ ./python -m perf timeit -s 'to_bytes=int.to_bytes' 'to_bytes(1, 4, "little")'
Reference: ~154 ns
Replace int_to_bytes_impl() body with:
PyBytes_FromStringAndSize("1", 1)
=> ~120 ns (-34 ns)
Replace int_to_bytes() body with:
return int_to_bytes_impl(self, 4, NULL, 1);
=> ~76 ns (-44 ns)
_PyArg_ParseStackAndKeywords() with _PyArg_Parser{"nU|$p:to_bytes"} takes 44 ns on a total of 154 ns. 29% of the runtime is spent on parsing arguments.
If you want to optimize further int.to_bytes(), IMHO we should explore the issue #29419: "Argument Clinic: inline PyArg_UnpackTuple and PyArg_ParseStack(AndKeyword)?".
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29300>
_______________________________________
More information about the Python-bugs-list
mailing list