root/doc/html/timer.html @ 264

Revision 264, 2.9 kB (checked in by smidl, 15 years ago)

doc

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3<title>mixpp: Using timers to measure execution time</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5<link href="tabs.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.5.6 -->
8<div class="navigation" id="top">
9  <div class="tabs">
10    <ul>
11      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
12      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
13      <li><a href="modules.html"><span>Modules</span></a></li>
14      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
15      <li><a href="classes.html"><span>Classes</span></a></li>
16      <li><a href="files.html"><span>Files</span></a></li>
17    </ul>
18  </div>
19</div>
20<div class="contents">
21<h1><a class="anchor" name="timer">Using timers to measure execution time </a></h1>In this example we are using the Real_Timer class to measure the execution time of a simple program. The Real_Timer class is included in the itmisc library.<p>
22<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;itpp/itbase.h&gt;</span>
23
24<span class="keyword">using namespace </span>itpp;
25
26<span class="comment">//These lines are needed for use of cout and endl</span>
27<span class="keyword">using</span> std::cout;
28<span class="keyword">using</span> std::endl;
29
30<span class="keywordtype">int</span> main()
31{
32  <span class="comment">//Declare the scalars used:</span>
33  <span class="keywordtype">long</span> i, sum, N;
34
35  <span class="comment">//Declare tt as an instance of the timer class:</span>
36  Real_Timer tt;
37
38  <span class="comment">//Initiate the variables:</span>
39  N = 1000000;
40  sum = 0;
41
42  <span class="comment">//Start and reset the timer:</span>
43  tt.tic();
44
45  <span class="comment">//Do some processing</span>
46  <span class="keywordflow">for</span> (i = 0; i &lt; N; i++) {
47    sum += i;
48  }
49
50  <span class="comment">// Print the elapsed time</span>
51  tt.toc_print();
52
53  <span class="comment">//Print the result of the processing:</span>
54  cout &lt;&lt; <span class="stringliteral">"The sum of all integers from 0 to "</span> &lt;&lt; N - 1 &lt;&lt; <span class="stringliteral">" equals "</span> &lt;&lt; sum &lt;&lt; endl;
55
56  <span class="comment">//Exit program:</span>
57  <span class="keywordflow">return</span> 0;
58
59}
60</pre></div><p>
61When you run this program, the output will look something like this:<p>
62<div class="fragment"><pre class="fragment">Elapsed time = 0.000797055 seconds
63The sum of all integers from 0 to 999999 equals 1783293664
64</pre></div> </div>
65<hr size="1"><address style="text-align: right;"><small>Generated on Fri Feb 6 19:49:57 2009 for mixpp by&nbsp;
66<a href="http://www.doxygen.org/index.html">
67<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
68</body>
69</html>
Note: See TracBrowser for help on using the browser.