Problem with timeit

Bob van der Poel bob at mellowood.ca
Fri Dec 15 13:52:35 EST 2017


I get a very short delay when doing the calculation.  1.90734863281e-06 to
be precise.

But, printing the result takes much longer. 4.82930707932 seconds.


On Fri, Dec 15, 2017 at 6:47 AM, Paul Moore <p.f.moore at gmail.com> wrote:

> 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
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 

**** Listen to my FREE CD at http://www.mellowood.ca/music/cedars ****
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bob at mellowood.ca
WWW:   http://www.mellowood.ca



More information about the Python-list mailing list