Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 5
    exactly what i want :) ... but you guys convinced me to use the python profiler Commented Mar 29, 2011 at 20:31
  • 3
    Looks like this assumes that the time.time() reports time in microseconds since the epoch? The documentation says it reports time in seconds docs.python.org/2/library/time.html#time.time. Commented Dec 13, 2014 at 1:02
  • This can't take effect, after using yield in func. How can I still using this method and can use yield? Commented May 3, 2015 at 12:05
  • def timing(f): def wrap(*args, **kwargs): time1 = time.time() ret = f(*args, **kwargs) time2 = time.time() print '%s function took %0.3f ms' % (f.func_name, (time2-time1)*1000) return ret return wrap Commented Jul 10, 2016 at 22:37
  • 1
    what's the disadvantage of writing it yourself? Isn't storing a list of elapsed times and examining their distribution simple enough? Commented Jan 17, 2018 at 16:36