timeutils package

Module contents

A set of methods and classes to accurately measure elapsed time.

See https://gitlab.com/cmick/timeutils for more information.


>>> from timeutils import Stopwatch
>>> sw = Stopwatch(start=True)
>>> sw.elapsed_seconds
>>> str(sw.stop())
>>> sw.elapsed.human_str()
'1 min, 30 secs'

See also

Documentation of the Stopwatch class.


Returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

timeutils.timeit(func, number=1000, repeat=1, args=None, kwargs=None)[source]

Measures the execution time of the provided function.

  • func (Callable) – function to be executed
  • number (int) – number of executions (1000 by default)
  • repeat (int) – indicates the number of times the time is measured; if greater than 1, a list of results is returned.
  • args (tuple,list) – positional arguments to be passed to function func
  • kwargs (dict[str,Any]) – keyword arguments to be passed to function func

measured time, or list of time measurements if repeat > 1

Return type:

TimeSpan or list[TimeSpan]

New in version 0.3.0.