Ask Your Question
0

Record output of timeit in variable

asked 2012-04-03 00:49:33 -0500

chaesloc2 gravatar image

updated 2012-04-03 02:59:37 -0500

Jason Grout gravatar image

How can I record in a variable the amount of time taken by a function? I read somewhere that timeit is the good way to time stuff, but it seems to print its output instead of returning it.

If possible, I would prefer not to redirect streams or redefine print, etc.


EDIT: got it, leaving the question for reference.

timeit("blah",seconds=True)

returns a number.

This should probably get a mention in 'timeit?'.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-04-03 07:08:14 -0500

When I execute timeit?, I see

OUTPUT:

This method prints the timing information and does not return
anything, except if the option "seconds=True" was passed, in which
case the wall time in seconds is returned.

I suppose it could be more prominent, but it is there.

edit flag offensive delete link more

Comments

That's not what I see; I don't get an OUTPUT section. I suppose my version is too old (4.7.2). Anyway, thanks!

chaesloc2 gravatar imagechaesloc2 ( 2012-04-03 08:15:35 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-04-03 00:49:33 -0500

Seen: 133 times

Last updated: Apr 03 '12