[Python-ideas] adding a timeit.Timer context manager and decorator to time code/functions

2020-11-27 Thread sdementen
When optimizing code, I often need to timeit a part of code or a function. I am using then the following class ``` import logging import time from functools import wraps from typing import Optional _logger = logging.getLogger("Timer") class Timer: def __init__(self, description: Optional[str]

[Python-ideas] Re: adding a timeit.Timer context manager and decorator to time code/functions

2020-11-29 Thread sdementen
The feature I am looking for is more about timing a code block or a function while running the code in dev/production. Not about timing it for benchmarking purposes. To use timeit (or the current Timer class), one has to write the stmt as a string which is not convenient (yet I understand that i

[Python-ideas] Re: adding a timeit.Timer context manager and decorator to time code/functions

2020-11-29 Thread sdementen
I have read the documentation of the timeit module and also you can pass a function (without arguments) to it (e.g. https://stackoverflow.com/questions/5086430/how-to-pass-parameters-of-a-function-when-using-timeit-timer). My needs are: - simple way to instrument my code to log time for a functi