A nice Python timer class

in «tip» by Michael Beard
Tags: , , , ,

Python Timer Functions: Three Ways to Monitor Your Code

The article Python Timer Functions: Three Ways to Monitor Your Code looks like it's a pretty good tutorial that leaves you with a usable timer for your code. You can use it as:

  • a class
  • a decorator
  • context manager

All useful and have different reasons to use them.

It's also installable with pip (python -m pip install codetiming) or you can just grab the code from above.

This tutorial has some interesting stuff in it. Decorators and as a context manager, which I thought was interesting and probably should know.