Skip to content

Instantly share code, notes, and snippets.

Last active Oct 23, 2016
What would you like to do?
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
# 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

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