Skip to main content

A (BSD licensed) context manager for timing execution.

Project description

A (BSD licensed) context manager for timing execution. Useful for benchmarking everyday Python code easily/cleanly.

Usage

Usage is trivial. Simply wrap your code in a Timer context manager. Example:

from chrono import Timer

with Timer() as timed:
    # Put whatever logic you want here.
    # ``for`` loops are great here for timing things that are very fast.

print("Time spent: {0} seconds".format(timed.elapsed))

Requirements

  • Python 2.6+ or Python 3.3+ (may work on Python 2.5)

License

BSD

Shortcomings

This is implemented in pure Python, so it doesn’t have the accuracy a C extension would have. There’s also overhead for the context manager function calls, so don’t use this to bench C code.

That said, for most everyday usage of Python, it’s very helpful.

Running Tests

Setup:

$ git clone https://github.com/toastdriven/chrono.git
$ cd chrono
$ virtualenv -p python3 env3
$ . env3/bin/activate
$ pip install nose

Running:

$ nosetests -s -v tests.py

chrono is maintained with 100% passing tests at all times.

Changelog

v1.0.0
  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chrono-1.0.0.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file chrono-1.0.0.tar.gz.

File metadata

  • Download URL: chrono-1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for chrono-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1925c9fff573119e96e2099ec141598bf00679ed8b8babc7cac41b3c4275d5e1
MD5 add09d122000171ed40683b1b6751b3a
BLAKE2b-256 cf9e341bf9b50cdc9492404bc309792e49f2d0bbc014b72d72979eec63bf711a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page