Skip to content

A precise and lightweight stopwatch built on top of perf_counter, which can be used as a replacement for perf_counter that returns absolute timing starting from zero.

License

Notifications You must be signed in to change notification settings

morefigs/stoppy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stoppy ⏱

A precise and lightweight stopwatch built on top of perf_counter, which can be used as a replacement for perf_counter that returns absolute time starting from zero.

The stopwatch can optionally be started automatically by calling time(True) instead of start(), which can streamline usage when polling the time repeatedly.

Installation

Install from PyPI via:

pip install stoppy

Usage

Basic usage is as follows:

from time import sleep
from stoppy import Stopwatch

with Stopwatch(start=True) as stopwatch:
    sleep(0.1)
    stopwatch.stop()
    print(stopwatch.time())
    stopwatch.reset()

It can also be used as a direct replacement for perf_counter that returns absolute time starting from zero:

from stoppy import Stopwatch

with Stopwatch() as stopwatch:
    # Calling `stopwatch.time(True)` is equivalent to calling `perf_counter()`, but starts from exactly zero
    print(stopwatch.time(True))

For all usage examples see examples/.

About

A precise and lightweight stopwatch built on top of perf_counter, which can be used as a replacement for perf_counter that returns absolute timing starting from zero.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages