Skip to content

ppi-agray/timethis

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This module provides a context manager for measuring execution times:

>>> from timethis import timethis
>>> with timethis('computing large sum'):
...     x = sum(range(10**7))
...
computing large sum: 0.203 seconds

Usage of timethis can be nested:

>>> with timethis('figuring things out'):
...     with timethis('computing large sum'):
...         x = sum(range(10**7))
...     with timethis('finding some primes'):
...         y = [2] + [i for i in range(3, 10**4) if all(i % j != 0 for j in range(2, i // 2 + 1))]
...
│ computing large sum: 0.205 secondsfinding some primes: 0.305 seconds
figuring things out: 0.510 seconds

It's easy to use (for example) logging instead of print:

>>> import logging
>>> with timethis('computing large sum', logging.warning):
...     x = sum(range(10**7))
...
WARNING:root:computing large sum: 0.218 seconds

About

Context manager for measuring execution times

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 55.1%
  • Makefile 44.9%