0

To profile a function one can use:

import cProfile
print cProfile.run('foo()')

Is it possible to use vmprof in similar way, i.e. just to profile one function from within the code? I'm asking because the linked docs only shows how to run it from command line:

python -m vmprof <program.py> <program parameters>
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117

1 Answers1

1

Yes, you do import vmprof; vmprof.enable(); vmprof.disable() Details are here: http://vmprof.readthedocs.io/en/latest/#api

fijal
  • 3,190
  • 18
  • 21
  • Thanks! But there it says `fileno` in `vmprof.enable()`, I assume it means it needs a file-like object to write to, so it can later display the statistics with `vmprof.read_profile()`, isn't it possible to just print it (to stdout), like with the cProfiler example above? – Ecir Hana May 17 '16 at 17:57
  • the print-to-stdout is generally discouraged (you should rather use the web view) – fijal May 20 '16 at 08:02