[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-12 Thread STINNER Victor
STINNER Victor added the comment: My main motivation was to use calloc() (issue #21419) for 2**n. It looks like using calloc() for this is only useful for very rare cases (very large value of n: result larger than 1 MB). I close the issue. -- resolution: -> rejected status: open -> cl

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-11 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis : -- nosy: +Arfrever ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-04 Thread Antoine Pitrou
Antoine Pitrou added the comment: I agree with Mark, there doesn't seem to be a strong point in favour of this optimization. -- ___ Python tracker ___ __

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-04 Thread Mark Dickinson
Mark Dickinson added the comment: Victor, can you demonstrate any cases of real code where this optimization makes a significant difference? There are many, many tiny optimisations we *could* be making in Objects/longobject.c; each of those potential optimisations adds to the cost of maintain

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-03 Thread STINNER Victor
STINNER Victor added the comment: pow2_specialized.patch: here is a different approach, a little bit faster. I wrote a dedicated long_pow2() function which computes 2**k. Arguments in favor of pow2_specialized.patch instead of pow2.patch: - it's a little bit faster - don't touch long_lshift(),

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-03 Thread Stefan Behnel
Stefan Behnel added the comment: LGTM, can't see a case where this might go wrong (errors and type checks are handled before the added code). It also seems a sufficiently common case to optimise it internally. The 2**n spelling is easier to read and to get right than the shifting, so it's good

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-02 Thread STINNER Victor
STINNER Victor added the comment: Oh, the patch implements another micro-optimization: "(x << 0) is x" becomes True. I included it in the same patch to reduce the overhead for 2 ** 0. -- nosy: +josh.rosenberg, pitrou, serhiy.storchaka ___ Python trac

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-02 Thread STINNER Victor
Changes by STINNER Victor : -- nosy: +mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-02 Thread STINNER Victor
STINNER Victor added the comment: Results of bench_pow2.py on Linux. Common platform: CPU model: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz Platform: Linux-3.13.9-200.fc20.x86_64-x86_64-with-fedora-20-Heisenbug Timer: time.perf_counter Python unicode implementation: PEP 393 Timer info: namespace(a

[issue21420] Optimize 2 ** n: implement it as 1 << n

2014-05-02 Thread STINNER Victor
New submission from STINNER Victor: The algorithm for 2 ** n (long_pow) is slower than 1 << n algorithm (long_lshift). I propose to compute x**y as 1<= 0. Attached patch implements this idea. According to my microbenchmark, it is 4x faster to small power (2**0 .. 2**1024) and up to 340x faster