PROFILING IN PYTHON
John
Saturday, December 21, 2013
introduction to the profiler
• A profiler is a program descibes the run time
performance of a program.
• Python standard l...
Quick example
Profile an application
1. use command line:
$ python -m cProfile myscript.py
2. or add into code with main f...
Cython profiling basic
Enable it for source file
• profiling can be enabled by
adding at the top of file
#cython: profile=...
Reference
• http://docs.python.org/2/library/profile.html
Reference
• http://docs.python.org/2/library/profile.html
Profiling in python
Upcoming SlideShare
Loading in...5
×

Profiling in python

154

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
154
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Profiling in python

  1. 1. PROFILING IN PYTHON John Saturday, December 21, 2013
  2. 2. introduction to the profiler • A profiler is a program descibes the run time performance of a program. • Python standard library provide 3 difference profiler: – cProfile : is recommende for most users. – profile: a pure python module whose interface imitated by cProfile – hotshot: an experimental C module that focused on minimizing the overhead of profiling
  3. 3. Quick example Profile an application 1. use command line: $ python -m cProfile myscript.py 2. or add into code with main function: impor cProfile cProfile.run(‘main()’) The result looks like:
  4. 4. Cython profiling basic Enable it for source file • profiling can be enabled by adding at the top of file #cython: profile=True • Use a special decorator disable profiling for one function only: cimport cython @cython.profile(False) def my_func(): pass Use pstats module review the profile import pstats p = pstats.Stats(‘fooprof’) p.strip_dirs().sort_stats(‘time’) .print_stats()
  5. 5. Reference • http://docs.python.org/2/library/profile.html
  6. 6. Reference • http://docs.python.org/2/library/profile.html
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×