0

How should i check the execution time for a sub instruction in python? The execution time for any instruction is easily available by adding %time before calling the function:

%time function call

now i have to know what really consumes time in a 3 level for loop (it is obvious that 3 for loops within each other will increase the time 3 fold). here's the code:

candidates = (known([word]).union(known(edits1(word)))).union(known_edits2(word).union(known_edits3(word)) or [word])

where,

def known_edits2(word):
    return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS)
def known_edits3(word):
    return set(e3 for e1 in edits1(word) for e2 in edits1(e1) for e3 in edits1(e2) if e3 in NWORDS)

I need to find out whether the iteration is taking more time or the multiple calls to edits1. So i need to find the time for each bit. i looked up and found about timeit function , but being a beginner i do not know how to put it to use.

Hypothetical Ninja
  • 3,920
  • 13
  • 49
  • 75

0 Answers0