Ask Your Question
0

Record output of timeit in variable

asked 2012-04-03 07:49:33 +0200

chaesloc2 gravatar image

updated 2012-04-03 09:59:37 +0200

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 14:08:14 +0200

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 15:15:35 +0200 )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 07:49:33 +0200

Seen: 326 times

Last updated: Apr 03 '12