Best search algorithm to find condition within a range

Serhiy Storchaka storchaka at gmail.com
Tue Apr 7 16:57:50 EDT 2015


On 07.04.15 22:28, Ian Kelly wrote:
> On Tue, Apr 7, 2015 at 1:19 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>>> % and probably // call divmod internally and toss one of the results.
>>> Slightly faster (5.7 versus 6.1 microseconds on my machine) is
>>
>> Not on my box.
>>
>> $ python3 -m timeit -s "n = 1000000; x = 42" "n % x; n // x"
>> 10000000 loops, best of 3: 0.105 usec per loop
>> $ python3 -m timeit -s "n = 1000000; x = 42" "divmod(n,x)"
>> 10000000 loops, best of 3: 0.124 usec per loop
>
> But curiously, if I time the whole function, then my results mirror
> yours; I wonder why that is. I don't see anything obvious in the
> disassembly that would explain it.

Try large numbers.




More information about the Python-list mailing list