Ask Your Question
0

Record output of timeit in variable

asked 13 years ago

chaesloc2 gravatar image

updated 13 years ago

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?'.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 13 years ago

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.

Preview: (hide)
link

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 ( 13 years ago )

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: 13 years ago

Seen: 361 times

Last updated: Apr 03 '12