[Python-ideas] add a time decorator to timeit.py
Amjad Ben Hedhili
amjadhedhili at outlook.com
Sun Oct 7 11:51:49 EDT 2018
@Steven D'Aprano<mailto:steve at pearwood.info> , I know you didn't ask for the implementation, but it does supports the idea and it contains comments describing how it's used.
@Chris Angelico<mailto:rosuav at gmail.com>, I don't know if it needs to be further customizable (apart from a repeat keyword maybe) as it's meant to be similar to the timeit function, and it's not meant to be complicated + you can use this argument for basically any function in the standard library as it might not be customizable enough for someone's needs, I don't know if that's a big problem in the first place as there are functions in the standard library with lots of keywords (e.g the Popen constructor with 18 kw).
I see that it deserves to be in the std library as the current way might not be suitable for many, i mean:
`timeit.timeit("func_to_time(a, b)", setup="from __main__ import a, b")
`timeit.timeit("func_to_time(a, b)", globals=globals())`
is not as:
when you don't want it for now you simply comment the decorator.
Also consider the case where you have a dozen of functions and methods to measure, it'll be tedious to go with timeit version.
in addition other languages that compete with python have easy ways to measure times in their standard library that are more pythonic than python itself (e.g Julia with @timev, @timed, @elapsed macros, Kotlin with the measureTimeMillis and measureNanoTime functions ...)
and the implementation is open for change, it can be made better.
De : Python-ideas <python-ideas-bounces+amjadhedhili=outlook.com at python.org> de la part de Chris Angelico <rosuav at gmail.com>
Envoyé : dimanche 7 octobre 2018 05:44
À : python-ideas
Objet : Re: [Python-ideas] add a time decorator to timeit.py
On Sun, Oct 7, 2018 at 11:34 PM Steven D'Aprano <steve at pearwood.info> wrote:
> Unfortunately, not every good idea can or will make it into the std lib.
> Even if the idea is good, we might decide that it belongs as a third-
> party library, or that the benefit is not enough to make up for the cost
> in effort or complexity. Or the idea is simply too controversial.
Or just too detaily. The given function has four keyword arguments
that vary its behaviour slightly; if it gets into the stdlib, someone
will ask for a way to control the output format, someone else will
request that it be able to send to stderr instead of stdout, etc, etc,
and suddenly the proposed function has two dozen kwargs. One of the
powerful tools available to a programmer is having *your own* debug
library, without having to worry about what other people would do that
might be similar.
-0.5 on adding to the stdlib, -0 on putting on PyPI (I wouldn't bother
looking on PyPI for something like this - I'd just write my own,
specific to the need).
Python-ideas mailing list
Python-ideas at python.org
Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas