time.perf_counter

A Python function that returns a high-resolution clock reading in seconds, used to time short pieces of code.

In more detail

Call it before and after the code you want to measure and subtract the two values. Only the difference is meaningful; the starting point of the clock is undefined. For reliable numbers, repeat the operation many times in a loop and time the whole loop.

Example

t0 = time.perf_counter(); work(); elapsed = time.perf_counter() - t0

Related terms

Taught in

References