Message220688
Perhaps a time-elapsed context manager would be a better fit in the contextlib module (which contains more general purpose
macro-level tools usable for many different tasks)
rather than the timeit module (which is more
narrowly tailored to high-quality reproducable in-vitro performance analysis at a fine-grained level).
> It's a very common task.
That said, the task is sometimes solved in different ways. Hard-wiring this to "print" would preclude its use in cases where you want to save the result to a variable, log it, or build some cumulative total-time statistics.
Also, I think it ignores some of the realities about how difficult it is to do meaningful performance analysis.
The "cumsum" example isn't the norm. Most code is harder to time and doesn't have a high-volume tight-loop that you can that you can easily wrap a course-grained context manager around. Getting reproduceable timings (creating a consistent setup, using repeated calls to average-out noise, and isolating the part you want to test) can be tricky in the middle of real applications.
I occasionally have code where the proposed content manager would have been nice (saving me from typing the usual start=time() ... end=time()-start pairs). However, most of the time this technique is too simple and something like Robert Kern's line-profiler or cProfile are a better fit for identifying hotspots. |
|
Date |
User |
Action |
Args |
2014-06-16 02:09:22 | rhettinger | set | recipients:
+ rhettinger, gvanrossum, tim.peters, georg.brandl, ncoghlan, giampaolo.rodola, ezio.melotti, steven.daprano, dmoore |
2014-06-16 02:09:22 | rhettinger | set | messageid: <1402884562.62.0.868752551624.issue19495@psf.upfronthosting.co.za> |
2014-06-16 02:09:22 | rhettinger | link | issue19495 messages |
2014-06-16 02:09:20 | rhettinger | create | |
|