On Sun, Nov 29, 2020 at 10:36 PM <sdemen...@gmail.com> wrote:

>
> My needs are:
> - simple way to instrument my code to log time for a function or a code
> block (I am not writing a specific script to time/benchmark a specific code)
> - have the timing sent to some logger
> - be the less intrusive possible
>
> With the Timer proposed here above (bad naming as Timer already exists in
> the timeit module, maybe Clocker ?), I can simply:
> - decorate a function with it and I am done
> - wrap an existing code with it as context manager
>

timeit is indeed pretty awkward. Personally, I use iPython's @timeit for
quick an dirty timing of a single function, or a few lines of code.

But I'm not sure a context manager or decorator is needed, either. They
are not hard to write. IN fact, I've seen both used as examples in
tutorials, etc, including some of my own :-)

https://uwpce-pythoncert.github.io/ProgrammingInPython/modules/Decorators.html#nested-decorators
and
https://uwpce-pythoncert.github.io/ProgrammingInPython/exercises/context-managers-exercise.html#timing-context-manager

(those are very simple, more robust versions would be good)

I'd be very surprised if there wasn't something on PyPi as well. -- have
you looked?

I think one reason this hasn't been made more standard is that for inline
timing, it's not clear how the results should be stored / presented --
everyone will want to do that their own way (or do a proper profile).

But if you do figure out exactly what you want, and can't find it on PyPi,
you can write it, and then put it on PyPi, and/or propose it be added to
the std lib.

-CHB


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/K6A7JLEANU63NWL6HOB5PWWMLDISUW7G/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to