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
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") |