[Python-ideas] Timing hefty or long-running blocks of code
Ron Adam
ron3200 at gmail.com
Mon Jun 3 15:44:26 CEST 2013
On 06/02/2013 10:20 AM, Masklinn wrote:
> That's a profile. Note that you can add both timing and profiling with
> low syntactic overhead (via function decorators) through the
> profilehooks package (available on pypi): profilehooks.profile will do
> profiling runs on the function it decorates when that function is run,
> profilehook.timecall will just print the function's runtime. Both can be
> either immediate (print whatever's been collected for a call at the end
> of the call) or not immediate (print a summary of all calls when the
> program terminates):
Thanks, I'll definitely find this useful.
Seems like it would make a nice addition to the library.
>>> import profilehooks
>>> @profilehooks.timecall
... def immediate(n):
... list(xrange(n))
...
>>> immediate(40000)
immediate (<stdin>:1):
0.002 seconds
It would be nice if the output included the function arguments, if they are
not too long. When running a script that information isn't as obvious as
it is on a command line.
Cheers,
Ron
More information about the Python-ideas
mailing list