(Python 2.7.8, Windows)
there is so many questions already about this particular subject, but I cannot seem to get any of them working.
So, what I'm trying to accomplish is timing how long a function takes to execute.
I have functions.py and main.py in following fashion:
#functions.py
def function(list):
does something
return list
...
#main.py
import functions
...stuff...
while:
list = gets list from file
functions.function(list) <--- this needs to get timed
Now I tried time.time()
the start and end points first, but it's not accurate enough (difference tends to be 0.0), and after some googling it seems that this isn't the way to go anyway. Apparently what I should use(?) is timeit
module. However I cannot understand how to get the function into it.
Any help?
As you mentioned, there's a Python module made for this very task,
timeit
. Its syntax, while a little idiosyncratic, is quite easy to understand:stmt
is the function call to be measured, in your case:functions.function(list)
setup
is the code you need to create the context necessary forstmt
to execute, in your case:import functions; list = gets list from file
number
is how many timetimeit
would runstmt
to find its average execution time. You might want to change the number, since calling your function a million times might take a while.tl;dr: