Skip to content

Instantly share code, notes, and snippets.

@nok-ko
Last active November 4, 2019 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nok-ko/955e9279a64e46c23de5ac8d14b59e58 to your computer and use it in GitHub Desktop.
Save nok-ko/955e9279a64e46c23de5ac8d14b59e58 to your computer and use it in GitHub Desktop.
"""
Quickly time a function.
"""
import timeit
def quick_timeit(fname, case="", number=1000):
return timeit.timeit(stmt=f"{fname}({case})", setup=f"from __main__ import {fname}", number=number)
# usage:
## def some_fn(x,y): return x + y + min(x,y)
## def some_fn(*args): return sum(args) + min(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment