cprofile by running the following in the command linepython - cprofile cprof_example py if you try thatyou'll find that the results are outputted sorted by function name this makes it bit hard to get an idea of where the most time is spentso it' very common to specify sort order using the - flagpython - cprofile - cumulative cprof_example py largest one we saw function calls ( primitive callsin seconds ordered bycumulative time ncalls tottime percall cumtime percall filename:lineno(function cprof_example py: ( linalg py: (eigvals {numpy linalg lapack_lite dgeev __init__ py: ( {method 'randn' add_newdocs py: ( __init__ py: ( __init__ py: ( type_check py: ( __init__ py: ( numeric py: ( __init__ py: ( __init__ py: ( function_base py: (add_newdoc linalg py: (_assertfiniteonly the first rows of the output are shown it' easiest to read by scanning down the cumtime column to see how much total time was spent inside each function note that if function calls some other functionthe clock does not stop running cprofile records the start and end time of each function call and uses that to produce the timing in addition to the above command-line usagecprofile can also be used programmatically to profile arbitrary blocks of code without having to run new process ipython has convenient interface to this capability using the %prun command and the - option to %run %prun takes the same "command line optionsas cprofile but will profile an arbitrary python statement instead of while py filein [ ]%prun - - cumulative run_experiment( function calls in seconds ordered bycumulative time list reduced from to due to restriction ncalls tottime percall cumtime percall filename:lineno(function : ( cprof_example py: (run_experiment linalg py: (eigvalssoftware development tools www it-ebooks info