Skip to content

Instantly share code, notes, and snippets.

@SteadBytes
Created December 29, 2018 07:26
Show Gist options
  • Save SteadBytes/fe3e7a7e1029bb79381e29563e83857a to your computer and use it in GitHub Desktop.
Save SteadBytes/fe3e7a7e1029bb79381e29563e83857a to your computer and use it in GitHub Desktop.
Time python function
from functools import partial
import timeit
def measure_time(n, f, *args, **kwargs):
"""
Args:
n (int): number of tests
f (func): function to time
*args: any arguments to pass to f
"""
return timeit.timeit(partial(f, *args, **kwargs), number=n)
# measure_time(100, my_func, input_to_my_func, a_kwarg_to_my_func=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment