Hi
i was wondering the best way to time how long a function/program takes
i cant work out how to do it. I tried fiddling with the time module yet i keep
doing the wrong things.
lllllIllIlllI
178
Veteran Poster
Recommended Answers
Jump to PostExample using the timeit module:
def my_function(): return results if __name__ == '__main__': import timeit t = timeit.Timer("my_function()", "from __main__ import my_function") print t.timeit(1000)
Note that timeit() defaults to 1,000,000 iterations. If your function is somewhat slow, you may want to specify the number of iterations (1000 …
All 3 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.