Way to retrieve the value of %time?
Francesc Alted <[email protected]> Thu, 16 Jul 2015 20:22:01 +0200
| Newsgroups | gmane.comp.python.ipython.user |
|---|---|
| Message-ID | <CAFrp1vp=aV3HZTbW0uW2OrcW7YrxJxLa0OssQcUJn2NUCxOMGw@mail.gmail.com> |
--===============0822611526== Content-Type: multipart/alternative; boundary=001a1136b6aed1b887051b022559 --001a1136b6aed1b887051b022559 Content-Type: text/plain; charset=UTF-8 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 --001a1136b6aed1b887051b022559 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Hi,<div><br></div><div>I am trying to come up with a way o= f accessing the time measured by the magic %time.=C2=A0 That is, in:</div><= div><br></div><div>In [149]: %time sum(i for i in xrange(1000000))<div>CPU = times: user 118 ms, sys: 27.4 ms, total: 145 ms</div><div>Wall time: 121 ms= </div><div>Out[149]: 499999500000</div><div><br></div><div>is there a way t= o get the 121 ms value of the 'Wall time' above and put that in a v= ariable?=C2=A0 I know I can use something like:</div><div><br></div><div><d= iv>In [150]: from time import time</div><div><br></div><div>In [151]: t0 = =3D time(); sum(i for i in xrange(1000000)); mytime =3D time() - t0</div><d= iv><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 f= or tutorials, that I would rather prefer using it.</div><div><br></div><div= >Thanks!</div><div><br></div>-- <br><div class=3D"gmail_signature">Francesc= Alted</div> </div></div> --001a1136b6aed1b887051b022559-- --===============0822611526== 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 --===============0822611526==--