andrwcnln / tictoc

Fast, simple and accurate Python timing. Written in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A logo with the word tictoc followed by a stopwatch emoji A logo with the word tictoc followed by a stopwatch emoji

Fast, simple and accurate Python timing. Written in Rust.

badge badge badge

Installation

Install with pip.

$ python -m pip install tictoc

Usage

Import and initialise. The module must be initialised to be used!

import tictoc
t = tictoc.init()

Begin timing with tic(), and stop with toc().

t.tic()
# some code
t.toc()

When toc is called, the results are saved. They can be accessed with the following syntax:

t.results.{unit}

The available units are:

t.results.nanos   # u128
t.results.micros  # u128
t.results.millis  # u128
t.results.seconds # f64

Full example

import time

import tictoc
t = tictoc.init()

t.tic()       # start timing
time.sleep(3) # sleep for 3 seconds
t.toc()       # stop timing

print(t.results.seconds)
# >>> 3.000457715

About

Fast, simple and accurate Python timing. Written in Rust.


Languages

Language:Python 53.1%Language:Rust 46.9%