Skip to content

Instantly share code, notes, and snippets.

@say4n
Last active October 23, 2016 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save say4n/cfec3b0e0e1af77b6137ed3f2a75c40b to your computer and use it in GitHub Desktop.
Save say4n/cfec3b0e0e1af77b6137ed3f2a75c40b to your computer and use it in GitHub Desktop.
Python basic time profiler
from __future__ import print_function
import time
def profiler(any_func):
# get time before running the code
t1 = time.time()
# run the function itself to profile
any_func()
# get time after runnig the code
t2 = time.time()
print("Time needed to run : " + str(t2 -t1) + "s")

To use the profiler, just use import pyprofile and if the function to be profiled is named stupid_code use the profiler as follows

@pyprofile
def stupid_code():
    # do something stupid here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment