Guido rethinking removal of cmp from sort method
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Mar 25 01:46:52 EDT 2011
On Thu, 24 Mar 2011 18:32:11 -0700, Carl Banks wrote:
> It's probably the least justified builtin other than pow.
I don't know about that. Correctly, efficiently and *quickly*
implementing the three-argument version of pow is exactly the sort of
thing that should be in the built-ins, or at least the standard library.
[steve at sylar ~]$ python3 -m timeit -s "n=2" "(n**30000)%123456789"
1000 loops, best of 3: 633 usec per loop
[steve at sylar obfuscate]$ python3 -m timeit -s "n=2" "pow(n, 30000,
123456789)"
100000 loops, best of 3: 6.03 usec per loop
That's two orders of magnitude faster.
(You need the n=2 to defeat Python's compile-time constant folding,
otherwise timing measurements will be misleading.)
--
Steven
More information about the Python-list
mailing list