\section{Introduction}\label{timer_timerintro}
mlpack provides a simple timer interface for the timing of machine learning methods. The results of any timers used during the program are displayed at output by any command-\/line binding, when --verbose is given\+:


\begin{DoxyCode}
$ mlpack\_knn -r dataset.csv -n neighbors\_out.csv -d distances\_out.csv -k 5 -v
<...>
[INFO ] Program timers:
[INFO ]   computing\_neighbors: 0.010650s
[INFO ]   loading\_data: 0.002567s
[INFO ]   saving\_data: 0.001115s
[INFO ]   total\_time: 0.149816s
[INFO ]   tree\_building: 0.000534s
\end{DoxyCode}
\section{Timer A\+PI}\label{timer_usingtimer}
The \doxyref{mlpack\+::\+Timer}{p.}{classmlpack_1_1Timer} class provides three simple methods\+:


\begin{DoxyCode}
\textcolor{keywordtype}{void} Timer::Start(\textcolor{keyword}{const} \textcolor{keywordtype}{char}* name);
\textcolor{keywordtype}{void} Timer::Stop(\textcolor{keyword}{const} \textcolor{keywordtype}{char}* name);
timeval Timer::Get(\textcolor{keyword}{const} \textcolor{keywordtype}{char}* name);
\end{DoxyCode}


Each timer is given a name, and is referenced by that name. You can call {\ttfamily Timer\+::\+Start()} and {\ttfamily Timer\+::\+Stop()} multiple times for a particular timer name, and the result will be the sum of the runs of the timer. Note that {\ttfamily Timer\+::\+Stop()} must be called before {\ttfamily Timer\+::\+Start()} is called again, otherwise a std\+::runtime\+\_\+error exception will be thrown.

A {\ttfamily \char`\"{}total\+\_\+time\char`\"{}} timer is run by default for each mlpack program.\section{Timer Example}\label{timer_example}
Below is a very simple example of timer usage in code.


\begin{DoxyCode}
\textcolor{preprocessor}{#include <mlpack/core.hpp>}
\textcolor{preprocessor}{#include <mlpack/core/util/io.hpp>}
\textcolor{preprocessor}{#define BINDING\_TYPE BINDING\_TYPE\_CLI}
\textcolor{preprocessor}{#include <mlpack/core/util/mlpack_main.hpp>}

\textcolor{keyword}{using namespace }mlpack;

\textcolor{keywordtype}{void} mlpackMain()
\{
  \textcolor{comment}{// Start a timer.}
  Timer::Start(\textcolor{stringliteral}{"some\_timer"});

  \textcolor{comment}{// Do some things.}
  DoSomeStuff();

  \textcolor{comment}{// Stop the timer.}
  Timer::Stop(\textcolor{stringliteral}{"some\_timer"});
\}
\end{DoxyCode}


If the --verbose flag was given to this executable, the time that {\ttfamily \char`\"{}some\+\_\+timer\char`\"{}} ran for would be printed at the end of the program\textquotesingle{}s output. 