Once you have implemented a testcase which is running and doing what you want, the computation might still take longer than you expected. A program to visualize profile data of your code's run is [[http://kcachegrind.sourceforge.net/html/Home.html|KCachegrind]], which can be installed on a Ubuntu system by {{{sudo apt-get install kcachegrind}}}

== Profiling a whole computation ==

To profile the whole computation, start your testcase with{{{python -m lsprofcalltree your_testcase.py}}}and get a log file called `your_testcase.py.log`. Open this file with [[http://kcachegrind.sourceforge.net/html/Home.html|KCachegrind]] by{{{kcachegrind your_testcase.py.log}}}and analyze the graphs to get an idea of where the most time is spent in your computation.

== Profiling a single method ==

To profile a single method of your testcase, you have to add some lines to your code. The following lines shall serve you as an example for profiling a method called `profiled_method` with the arguments `arguments`.{{{#!pythonfrom cProfile import Profileprof = Profile()try: prof.runcall(lambda: profiled_method(arguments))finally: from lsprofcalltree import KCacheGrind kg = KCacheGrind(prof) import sys kg.output(open( "your_testcase_profiled_method.log", "w"))}}}You would get a log file called `your_testcase_profiled_method.log` which you can analyze with [[http://kcachegrind.sourceforge.net/html/Home.html|KCachegrind]].In `experiments/hedge/maxwell/maxwell-cuda.py` you can find an example for that.

== Plotting the computation time data ==

If you want to plot the computation time data, have look at the part of this Wiki that explains [[http://webapp.dam.brown.edu/wiki/SciComp/PythonHowTo/Plot|plotting graphs with matplotlib]].

Profiling Hedge

Once you have implemented a testcase which is running and doing what you want, the computation might still take longer than you expected. A program to visualize profile data of your code's run is KCachegrind, which can be installed on a Ubuntu system by

sudo apt-get install kcachegrind

Profiling a whole computation

To profile the whole computation, start your testcase with

python -m lsprofcalltree your_testcase.py

and get a log file called your_testcase.py.log. Open this file with KCachegrind by

kcachegrind your_testcase.py.log

and analyze the graphs to get an idea of where the most time is spent in your computation.

Profiling a single method

To profile a single method of your testcase, you have to add some lines to your code. The following lines shall serve you as an example for profiling a method called profiled_method with the arguments arguments.