[issue6713] Integer & Long types: Performance improvement of 1.6x to 2x for base 10 conversions
Mark Dickinson
report at bugs.python.org
Wed Sep 16 21:41:16 CEST 2009
Mark Dickinson <dickinsm at gmail.com> added the comment:
Updated patch, with minor changes:
- remove an incorrect Py_DECREF(str)
- rename _PyLong_ToDecimal; no need for the _Py prefix, since this
function isn't shared across files
- absorb special case for 0 into the rest of the code
- whitespace and indentation fixes
Not that it matters much, but it's curious that on my machine (gcc-4.2, OS
X 10.6.1, x64-64) it's significantly faster (~6% increase in str() speed
for large integers) to use the line:
pout[j] = z - (twodigits)hi * _PyLong_DECIMAL_BASE;
in the middle of the inner loop, rather than the line:
pout[j] = z - hi * _PyLong_DECIMAL_BASE;
I'm wondering whether this is just a quirk of my OS/compiler combination,
or whether there's a good reason for this difference. The lines are
functionally equivalent, since the result is reduced modulo 2**32 either
way, but the first line involves a 32x32->64 multiplication and a 64-bit
subtraction, where the second involves a 32x32->32 multiplication and a
32-bit subtraction; the generated assembly code for the second line is
also one instruction shorter (there's a move opcode saved somewhere).
----------
Added file: http://bugs.python.org/file14902/long_decimal_conversion_py3k_2.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6713>
_______________________________________
More information about the Python-bugs-list
mailing list