This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Oren Milman
Recipients Oren Milman, mark.dickinson, serhiy.storchaka
Date 2016-06-17.12:35:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1466166925.22.0.253272969031.issue27298@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-06-17 12:35:25Oren Milmansetrecipients: + Oren Milman, mark.dickinson, serhiy.storchaka
2016-06-17 12:35:25Oren Milmansetmessageid: <1466166925.22.0.253272969031.issue27298@psf.upfronthosting.co.za>
2016-06-17 12:35:25Oren Milmanlinkissue27298 messages
2016-06-17 12:35:24Oren Milmancreate