Problem with timeit
Paul Moore
p.f.moore at gmail.com
Fri Dec 15 08:47:10 EST 2017
On 15 December 2017 at 13:25, ast <nomail at com.invalid> wrote:
> On my computer it takes roughtly 4 s, mesured with a watch.
Is your computer particularly old? On my PC, the time it takes to run
x=123456**123456 at the Python interpreter prompt is barely
noticeable.
> I can't do "len(str(x))" to know the size, I have to kill the process
Took a few seconds (5-10s) on my PC, and returned 628578.
> But x.bit_length() answers 2088091, so x should have about
> 600000 digits
Yep, that's what I get
>
> If I measure execution time:
>
>>>> t=time(); x=123456**123456; print(time()-t)
>
> 0.0
Same here.
> There is still something wrong
As far as I can see, it's in your manual measurement. All of the code
you've provided gives the same results on my PC as on yours, but your
manual measurements differ drastically from mine (and my manual
measurements match what I'd expect given results of timeit/time.time
whereas yours don't...).
Paul
More information about the Python-list
mailing list