Skip to main content

Simple stopwatch to easily print the elapsed time of a set of operations

Project description

Computational Stopwatch

Simple stopwatch to easily print the elapsed time of a set of operations. It's a minimalistic library, but it is very useful in many real cases.

Usage

The easiest way to use this tool is in conjunction with the with python statement.

>> from computational_stopwatch import Stopwatch
>>
>> with Stopwatch():
>>  time.sleep(3) # <- simulates a long computation 
Elapsed time 0:00:03.003106

anything within the scope of the with statement will count against the elapsed time. An optional task name to be printed along the elapsed time (e.g. for better identification in a log) can be set in the constructor.

Alternatively, the class can be directly instantiated and the print function explicitly called.

>> sw = Stopwatch()
>> time.sleep(3)
>> sw.print_elapsed_time()
Elapsed time 0:00:03.003280

The start time can be reset with the reset_time function and the get_elapsed_time method returns the unformatted elapsed time, which is useful for numerical comparisons.

Versions History

v1.0.1

  • minor fixes

v1.0.0

  • first reelease

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

computational_stopwatch-1.0.1.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

computational_stopwatch-1.0.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

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