[New-bugs-announce] [issue34917] add time decorator to timeit.py

AmjadHD report at bugs.python.org
Sat Oct 6 19:46:30 EDT 2018


New submission from AmjadHD <amjadbenhedhili at outlook.com>:

I made this simple time decorator, it's not perfect but it does make python more pythonic :) :
it can be used as a decorator:
```
@timef
def fun_to_time(a, b):
    ...
```
or as a function call
`timef(print)("Hello world!")`
just a simple decorator no need for
`timeit.timeit("fun_to_time(a, b)", setup="from __main__ import a, b", number=1)`
it's also customizable as you can control number of repetitions, garbage collection, unit ...
and it produces a formatted output such as:
`fun_to_time: 24.1056 ms`.
It is somewhat badly written so waiting for your word people of wisdom :).
I think python needs this in the standard library as the current way is (sometimes) tedious.

----------
components: Library (Lib)
files: timeit.py
messages: 327261
nosy: amjad ben hedhili
priority: normal
severity: normal
status: open
title: add time decorator to timeit.py
type: enhancement
versions: Python 3.7
Added file: https://bugs.python.org/file47855/timeit.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34917>
_______________________________________


More information about the New-bugs-announce mailing list