Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Python
import timeit
duration = timeit.timeit("f()", setup="from __main__ import f")

Setup makes the function f accessible to timeit. Returned is the execution time in seconds
import time
start = time.time()
f()
end = time.time()
return end - start

This returns the duration in seconds.
(time (f))

New implementation...
< >
programming-idioms.org