2

Basically I want to find out, on a given function call how much time was spent within a particular module, including subcalls to functions in other modules as well. Any suggestion on how to achieve such a thing?

For example:

# foo.py

import bar

@time(bar)
def foo():

    ...
    bar.qux()
    ...
    bar.foobar()

# bar.py
import foofoo
import barbar

def qux():

    ...
    foofoo.foo()
    ...

def foobar():

    ...
    barbar.bar()
    ...

Call to foo in foo.py should return the total time spent inside the bar module(bar.py), which in the above case should include time spent inside barbar and foofoo.

Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74

2 Answers2

4

What you're looking for is a profiler. Read here for more:

How can you profile a python script?

http://docs.python.org/2/library/profile.html

Community
  • 1
  • 1
bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
-1

python

import timeit
help (timeit)
Steve Barnes
  • 27,618
  • 6
  • 63
  • 73