Message286781
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)?". |
|
Date |
User |
Action |
Args |
2017-02-02 13:15:48 | vstinner | set | recipients:
+ vstinner, larry, methane, python-dev, martin.panter, serhiy.storchaka |
2017-02-02 13:15:48 | vstinner | set | messageid: <1486041348.9.0.18913765479.issue29300@psf.upfronthosting.co.za> |
2017-02-02 13:15:48 | vstinner | link | issue29300 messages |
2017-02-02 13:15:48 | vstinner | create | |
|