Skip to content
/ tic-toc Public

Measure and track the wall and CPU time of defined scopes.

License

Notifications You must be signed in to change notification settings

nok/tic-toc

Repository files navigation

tic-toc

PyPI PyPI GitHub license

Measure and track the wall and CPU time of defined scopes in Python.
It's suitable for long-running applications which should be monitored.

Installation

$ pip install tic-toc

Usage

The following examples demonstrate the most simple usage:

Here you see the implicit variant with the with construct:

from tic_toc import Timer

with Timer('NAME') as timer:
    print('Scope: ' + timer.name)
    time.sleep(1)

Here you see the explicit variant without the with construct:

from tic_toc import Timer

timer = Timer('NAME')
timer.tic()  # or .start()
print('Scope: ' + timer.name)
time.sleep(1)
timer.toc()  # or .end()

The outputs are similar to each other:

# > NAME ...
# Scope: NAME
# < NAME [WALL: 1.0034s] [CPU: 0.0001s]

You can find more extended examples (e.g. with logging, tqdm or pandas) in the examples directory.

Parameters

class Timer(object):
    def __init__(self, name: str = None,
                 format_start: str = '> {name} ...',
                 format_end: str = '< {name} [WALL: {time_wall:.4f}s] [CPU: {time_cpu:.4f}s]',
                 to: Callable[[Any], None] = lambda msg: print(msg)):
  • name: str, optional, default: leading hash with four random digits, eg. #0512
  • format_start: str, optional, default: '> {name} ...'
  • format_end: str, optional, default: '< {name} [WALL: {time_wall:.4f}s] [CPU: {time_cpu:.4f}s]'
  • to: Callable[[Any], None], optional, default: lambda msg: print(msg)

You can change the visual string formats and the output method.

Sources

License

The module is Open Source Software released under the MIT license.

About

Measure and track the wall and CPU time of defined scopes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published