A simple way to measure execution time
Project description
TicToc - a simple way to measure execution time
TicToc provides a simple mechanism to measure the wall time (a stopwatch) with a reasonable accuracy.
Crete an object. Run tic()
to start the timer, toc()
to stop it. Repeated tic-toc's
will accumulate the time. The tic-toc pair is useful in interactive environments such as the
shell or a notebook. Whenever toc
is called, a useful message is automatically printed to stdout.
For non-interactive purposes, use start
and stop
, as they are less verbose.
Following is an example of how to use TicToc:
Usage examples
def leibniz_pi(n): ret = 0 for i in range(n * 1000000): ret += ((4.0 * (-1) ** i) / (2 * i + 1)) return ret tt_overall = TicToc('overall') # started by default tt_cumulative = TicToc('cumulative', start=False) for iteration in range(1, 4): tt_cumulative.start() tt_current = TicToc('current') pi = leibniz_pi(iteration) tt_current.stop() tt_cumulative.stop() time.sleep(0.01) # this inteval will not be accounted for by `tt_cumulative` print( f'Iteration {iteration}: pi={pi:.9}. ' f'The computation took {tt_current.running_time():.2f} seconds. ' f'Running time is {tt_overall.running_time():.2} seconds' ) tt_overall.stop() print(tt_overall) print(tt_cumulative)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for tictoc-borisgorelik-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30126bfac97920648c8ac8bcba547170df829005380ddec10bb9fab0e067b451 |
|
MD5 | b4b3f582d26e575d3d587b3d4562b3d6 |
|
BLAKE2-256 | b94fc0a7ab745f72d0fa707859bf4b7c82bb67721502df333147ad60fc47f99c |
Close
Hashes for tictoc_borisgorelik-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ef762de30240de2be9fca824dd53aeb6ae2ab160bb43124294e67f1ebb711a6 |
|
MD5 | 1049a87bd303c80a99ae8a0228a3ce23 |
|
BLAKE2-256 | 0f78424e8cf0b21543582473d68c929b83447f20e94419bd2b8f9890e3354375 |