[SciPy-user] Access to IPython's timeit result

Joe Kington jkington at wisc.edu
Sat Jul 4 14:44:34 EDT 2009


Hi Tom,

Have you looked at the timeit module?

http://docs.python.org/library/timeit.html

At least in 2.6, timeit.timeit() is builtin.  In older versions, you just
need to build a timeit.Time class instance and call it's timeit() function,
which returns an average over a number of executions (default=1000000).

If you really want the "best of 3" like ipython gives you, you can use the
repeat function of the timeit.Time module to return a list of the execution
times for each run.

Hope that helps,
-Joe

On Sat, Jul 4, 2009 at 12:02 PM, Joe Kington <jkington at geology.wisc.edu>wrote:

> Hi Tom,
>
> Have you looked at the timeit module?
>
> http://docs.python.org/library/timeit.html
>
> At least in 2.6, timeit.timeit() is builtin.  In older versions, you just
> need to build a timeit.Time class instance and call it's timeit() function,
> which returns an average over a number of executions (default=1000000).
>
> If you really want the "best of 3" like ipython gives you, you can use the
> repeat function of the timeit.Time module to return a list of the execution
> times for each run.
>
> Hope that helps,
> -Joe
>
> On Sat, Jul 4, 2009 at 8:31 AM, Tom K. <tpk at kraussfamily.org> wrote:
>
>>
>> Hi,
>>  Looking at timeit in IPython, you get a nice output e.g.
>>
>> In [14]: timeit x=range(100000)
>> 100 loops, best of 3: 5.75 ms per loop
>>
>> but what if I want to get access to that 5.75 ms number so I can write a
>> program to capture these over a list of "N" values and make a plot of time
>> versus "N"?
>>
>>  - Tom K.
>> --
>> View this message in context:
>> http://www.nabble.com/Access-to-IPython%27s-timeit-result-tp24334619p24334619.html
>> Sent from the Scipy-User mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> SciPy-user mailing list
>> SciPy-user at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090704/1add1c77/attachment.html>


More information about the SciPy-User mailing list