Re: Way to retrieve the value of %time?

Francesc Alted <[email protected]> Thu, 16 Jul 2015 20:35:36 +0200
Newsgroups gmane.comp.python.ipython.user
Message-ID <CAFrp1vp-cC4ob2mwO80qigY8a3skt6SF7rmLDK_U7yd9=0z0xg@mail.gmail.com>
--===============0140999285==
Content-Type: multipart/alternative; boundary=001a113626e863283c051b0256df

--001a113626e863283c051b0256df
Content-Type: text/plain; charset=UTF-8

Great, the next does what I want:

In [161]: t = %timeit -n1 -r1 -o sum(i for i in xrange(1000000))
1 loops, best of 1: 107 ms per loop

In [162]: t.all_runs[0]
Out[162]: 0.10677099227905273

But I agree that if %time could do the same that would awesome.

Regarding how I found this list, well google is your friend, and on the
other hand this is completely operational :P

Thanks anyway!
Francesc


2015-07-16 20:29 GMT+02:00 MinRK <[email protected]>:

> %time doesn't return a useful struct, but %timeit does, now. We should
> probably do the same thing for %time.
>
> -MinRK
>
> On Thu, Jul 16, 2015 at 11:22 AM, Francesc Alted <[email protected]> wrote:
>
>> Hi,
>>
>> I am trying to come up with a way of accessing the time measured by the
>> magic %time.  That is, in:
>>
>> In [149]: %time sum(i for i in xrange(1000000))
>> CPU times: user 118 ms, sys: 27.4 ms, total: 145 ms
>> Wall time: 121 ms
>> Out[149]: 499999500000
>>
>> is there a way to get the 121 ms value of the 'Wall time' above and put
>> that in a variable?  I know I can use something like:
>>
>> In [150]: from time import time
>>
>> In [151]: t0 = time(); sum(i for i in xrange(1000000)); mytime = time() -
>> t0
>>
>> In [152]: mytime
>> Out[152]: 0.10076594352722168
>>
>> but %time is so much convenient, specially for tutorials, that I would
>> rather prefer using it.
>>
>> Thanks!
>>
>> --
>> Francesc Alted
>>
>> _______________________________________________
>> IPython-User mailing list
>> [email protected]
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>>
>>
>
> _______________________________________________
> IPython-User mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>


-- 
Francesc Alted

--001a113626e863283c051b0256df
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Great, the next does what I want:<div><br></div><div><div>=
In [161]: t =3D %timeit -n1 -r1 -o sum(i for i in xrange(1000000))</div><di=
v>1 loops, best of 1: 107 ms per loop</div><div><br></div><div>In [162]: t.=
all_runs[0]</div><div>Out[162]: 0.10677099227905273</div></div><div><br></d=
iv><div>But I agree that if %time could do the same that would awesome.</di=
v><div><br></div><div>Regarding how I found this list, well google is your =
friend, and on the other hand this is completely operational :P</div><div><=
br></div><div>Thanks anyway!</div><div>Francesc</div><div><br></div></div><=
div class=3D"gmail_extra"><br><div class=3D"gmail_quote">2015-07-16 20:29 G=
MT+02:00 MinRK <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]=
" target=3D"_blank">[email protected]</a>&gt;</span>:<br><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr">%time doesn&#39;t return a useful struct, =
but %timeit does, now. We should probably do the same thing for %time.<span=
 class=3D"HOEnZb"><font color=3D"#888888"><div><br></div><div>-MinRK</div><=
/font></span></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote=
"><div><div class=3D"h5">On Thu, Jul 16, 2015 at 11:22 AM, Francesc Alted <=
span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">=
[email protected]</a>&gt;</span> wrote:<br></div></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-=
left:1ex"><div><div class=3D"h5"><div dir=3D"ltr">Hi,<div><br></div><div>I =
am trying to come up with a way of accessing the time measured by the magic=
 %time.=C2=A0 That is, in:</div><div><br></div><div>In [149]: %time sum(i f=
or i in xrange(1000000))<div>CPU times: user 118 ms, sys: 27.4 ms, total: 1=
45 ms</div><div>Wall time: 121 ms</div><div>Out[149]: 499999500000</div><di=
v><br></div><div>is there a way to get the 121 ms value of the &#39;Wall ti=
me&#39; above and put that in a variable?=C2=A0 I know I can use something =
like:</div><div><br></div><div><div>In [150]: from time import time</div><d=
iv><br></div><div>In [151]: t0 =3D time(); sum(i for i in xrange(1000000));=
 mytime =3D time() - t0</div><div><br></div><div>In [152]: mytime</div><div=
>Out[152]: 0.10076594352722168</div></div><div><br></div><div>but %time is =
so much convenient, specially for tutorials, that I would rather prefer usi=
ng it.</div><div><br></div><div>Thanks!</div><span><font color=3D"#888888">=
<div><br></div>-- <br><div>Francesc Alted</div>
</font></span></div></div>
<br></div></div><span class=3D"">__________________________________________=
_____<br>
IPython-User mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">IPython-User@sc=
ipy.org</a><br>
<a href=3D"http://mail.scipy.org/mailman/listinfo/ipython-user" rel=3D"nore=
ferrer" target=3D"_blank">http://mail.scipy.org/mailman/listinfo/ipython-us=
er</a><br>
<br></span></blockquote></div><br></div>
<br>_______________________________________________<br>
IPython-User mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]</a><br>
<a href=3D"http://mail.scipy.org/mailman/listinfo/ipython-user" rel=3D"nore=
ferrer" target=3D"_blank">http://mail.scipy.org/mailman/listinfo/ipython-us=
er</a><br>
<br></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div cla=
ss=3D"gmail_signature">Francesc Alted</div>
</div>

--001a113626e863283c051b0256df--

--===============0140999285==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
IPython-User mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/ipython-user

--===============0140999285==--