Oren Milman added the comment:

I did some micro-benchmarking, and it looks like bad news for my patch.

I wrote a simple C extension in order to call PyLong_AsUnsignedLongMask and 
PyLong_AsUnsignedLongLongMask from Python code (attached).
Then I ran the following micro-benchmarks using both the default CPython branch 
and my patched CPython:
1. small ints:
python.exe -m timeit -s "import capiWrapper" "print('bug') if any(i != 
capiWrapper.asUnsignedLongMaskWrapper(i) for i in range(10 ** 6)) else None"
python.exe -m timeit -s "import capiWrapper" "print('bug') if any(i != 
capiWrapper.asUnsignedLongLongMaskWrapper(i) for i in range(10 ** 6)) else None"
with the following results:
    asUnsignedLongMaskWrapper:
        default: 312 msec, patched: 353 msec
    asUnsignedLongLongMaskWrapper:
        default: 319 msec, patched: 356 msec

2. big ints:
python.exe -m timeit -s "import capiWrapper; bigInt = 10 ** 1000" "print('bug') 
if any((i & 0xffffffff) != capiWrapper.asUnsignedLongMaskWrapper(i) for i in 
range(bigInt, bigInt + 10000)) else None"
python.exe -m timeit -s "import capiWrapper; bigInt = 10 ** 1000" "print('bug') 
if any((i & 0xffffffffffffffff) != capiWrapper.asUnsignedLongLongMaskWrapper(i) 
for i in range(bigInt, bigInt + 10000)) else None"
with the following results:
    when bigInt = 10 ** 1000:
        asUnsignedLongMaskWrapper:
            default: 23.1 msec, patched: 21.5 msec
        asUnsignedLongLongMaskWrapper:
            default: 24.1 msec, patched: 21.7 msec

    when bigInt = 10 ** 150:
        asUnsignedLongMaskWrapper:
            default: 7.72 msec, patched: 7.82 msec
        asUnsignedLongLongMaskWrapper:
            default: 8.03 msec, patched: 7.99 msec


To sum it up, my patch degrades performance for ints smaller than 
(approximately) 10 ** 150, and improves performance for bigger ints. 

Seems to me like it doesn't worth it. 
I attached the patches diff file anyway, for the sake of documentation.

==========================================================================

That leaves us with the proposed changes in Modules/_testcapimodule.c.
The diff file for these (hopefully my final diff file for this issue) is also 
attached.

----------
Added file: http://bugs.python.org/file43433/capiWrapperModule.c

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27298>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to