42**1000000 is CPU time free

Cecil Westerhof Cecil at decebal.nl
Fri Jul 24 17:23:12 EDT 2015


On Friday 24 Jul 2015 22:54 CEST, candide wrote:

> Of course, computing 42**1000000 is not free:
>
>
> # ------------------
> import time
>
> a=time.clock()
>
> N=1000000
> 42**N
>
> b=time.clock()
>
> print("CPU TIME :", b - a)
> # ------------------
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> CPU TIME : 2.37
>
> real    0m2.412s
> user    0m2.388s
> sys     0m0.016s
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> So please, explain the following:
>
>
> # ------------------
> import time
>
> a=time.clock()
>
> 42**1000000
>
> b=time.clock()
>
> print("CPU TIME :", b - a)
> # ------------------
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> CPU TIME : 0.0
>
> real    0m2.410s
> user    0m2.400s
> sys     0m0.008s
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> (focus on the CPU TIME!!)

I cannot reproduce this. The first gives:
    CPU TIME : 0.6262789999999999
and the second:
    CPU TIME : 0.634364999999999

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list