Ezio Melotti added the comment:
I often write code like:
import time
start = time.time()
...
end = time.time()
print(end - start)
Usually I don't do this to measure accurately the performance of some piece of
code, but rather I do it for tasks that take some time (e.g. downloading a
Nick Coghlan added the comment:
I'm with Guido on this one - I don't believe there's a clean sweet spot to hit.
There *might* be a plausible case to be made for tracing functionality in the
logging module, but even there the number of options multiplies fast enough
that writing your own
Raymond Hettinger added the comment:
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
Steven D'Aprano added the comment:
On Mon, Jun 16, 2014 at 02:09:22AM +, Raymond Hettinger wrote:
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
Guido van Rossum added the comment:
I agree with Raymond -- this is a common pattern but there are many variations
that are hard to catch in a single implementation. E.g. at Dropbox we have a
decorator like this that lets you specify an identifier for the block you name,
and which logs the
Guido van Rossum added the comment:
FWIW, I definitely don't think this belongs in the timeit module, unless you
are going to treat that module as a namespace package, which I don't like
much (though in Java I think it's a pretty common pattern). If we have to have
it, contextlib sounds fine
Giampaolo Rodola' added the comment:
It might still be worth having a time elapsed decorator
This is exactly what I think. It's a very common task.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19495
Raymond Hettinger added the comment:
This idea is a bit at odds with the design of the rest of the time-it module
which seeks to:
* run small snippets of code in volume rather than trying to find bottlenecks
in large programs without interfering with their operation. The latter task
is more
Steven D'Aprano added the comment:
I have been using something like this for many years now and it is very handy.
I have an early version of the code posted here:
http://code.activestate.com/recipes/577896
Over the next week or so, I'll prepare a patch.
Because it's a new feature, it must be
New submission from Damien Moore:
It would be useful if timeit had a class like `timeblock` below that would
allow one to easily time code inside a `with` block:
import time
class timeblock:
def __init__(self,descr=''):
self.descr=descr
def __enter__(self):
Changes by Ezio Melotti ezio.melo...@gmail.com:
--
nosy: +ezio.melotti, georg.brandl, giampaolo.rodola
stage: - needs patch
versions: -Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python
3.5
___
Python tracker rep...@bugs.python.org
Giampaolo Rodola' added the comment:
I think I have already proposed something similar in past but I can't find any
reference on the tracker (so maybe I didn't after all).
BTW I have something like this [1] in a utils module I use across different
projects and I would definitively welcome an
12 matches
Mail list logo