Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Python

Idiom #125 Measure function call duration

measure the duration t, in nanoseconds, of a call to the function foo. Print this duration.

import time
t1 = time.perf_counter_ns()
foo()
t2 = time.perf_counter_ns()
print('Nanoseconds:', t2 - t1)

t1 and t2 are int
(time (foo))

time prints time elapsed, but in ms

New implementation...
< >
JPSII