1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
---|
5 | <title>mixpp: Using timers to measure execution time</title> |
---|
6 | <link href="tabs.css" rel="stylesheet" type="text/css"/> |
---|
7 | <link href="doxygen.css" rel="stylesheet" type="text/css"/> |
---|
8 | </head> |
---|
9 | <body> |
---|
10 | <!-- Generated by Doxygen 1.6.1 --> |
---|
11 | <script type="text/javascript"> |
---|
12 | <!-- |
---|
13 | function changeDisplayState (e){ |
---|
14 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
15 | var button=this.firstChild; |
---|
16 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
17 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
18 | sectionDiv.style.display='block'; |
---|
19 | button.src='open.gif'; |
---|
20 | }else{ |
---|
21 | sectionDiv.style.display='none'; |
---|
22 | button.src='closed.gif'; |
---|
23 | } |
---|
24 | } |
---|
25 | function initDynSections(){ |
---|
26 | var divs=document.getElementsByTagName('div'); |
---|
27 | var sectionCounter=1; |
---|
28 | for(var i=0;i<divs.length-1;i++){ |
---|
29 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
30 | var header=divs[i]; |
---|
31 | var section=divs[i+1]; |
---|
32 | var button=header.firstChild; |
---|
33 | if (button!='IMG'){ |
---|
34 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
35 | button=document.createElement('img'); |
---|
36 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
37 | } |
---|
38 | header.style.cursor='pointer'; |
---|
39 | header.onclick=changeDisplayState; |
---|
40 | header.id='dynheader'+sectionCounter; |
---|
41 | button.src='closed.gif'; |
---|
42 | section.id='dynsection'+sectionCounter; |
---|
43 | section.style.display='none'; |
---|
44 | section.style.marginLeft='14px'; |
---|
45 | sectionCounter++; |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | window.onload = initDynSections; |
---|
50 | --> |
---|
51 | </script> |
---|
52 | <div class="navigation" id="top"> |
---|
53 | <div class="tabs"> |
---|
54 | <ul> |
---|
55 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
56 | <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> |
---|
57 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
58 | <li><a href="files.html"><span>Files</span></a></li> |
---|
59 | </ul> |
---|
60 | </div> |
---|
61 | <div class="navpath"><a class="el" href="dev_guide.html">Howto Use BDM in C++ for your needs</a> |
---|
62 | </div> |
---|
63 | </div> |
---|
64 | <div class="contents"> |
---|
65 | |
---|
66 | |
---|
67 | <h1><a class="anchor" id="timer">Using timers to measure execution time </a></h1><p>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> |
---|
68 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <itpp/itbase.h></span> |
---|
69 | |
---|
70 | <span class="keyword">using namespace </span>itpp; |
---|
71 | |
---|
72 | <span class="comment">//These lines are needed for use of cout and endl</span> |
---|
73 | <span class="keyword">using</span> std::cout; |
---|
74 | <span class="keyword">using</span> std::endl; |
---|
75 | |
---|
76 | <span class="keywordtype">int</span> main() { |
---|
77 | <span class="comment">//Declare the scalars used:</span> |
---|
78 | <span class="keywordtype">long</span> i, sum, N; |
---|
79 | |
---|
80 | <span class="comment">//Declare tt as an instance of the timer class:</span> |
---|
81 | Real_Timer tt; |
---|
82 | |
---|
83 | <span class="comment">//Initiate the variables:</span> |
---|
84 | N = 1000000; |
---|
85 | sum = 0; |
---|
86 | |
---|
87 | <span class="comment">//Start and reset the timer:</span> |
---|
88 | tt.tic(); |
---|
89 | |
---|
90 | <span class="comment">//Do some processing</span> |
---|
91 | <span class="keywordflow">for</span> ( i = 0; i < N; i++ ) { |
---|
92 | sum += i; |
---|
93 | } |
---|
94 | |
---|
95 | <span class="comment">// Print the elapsed time</span> |
---|
96 | tt.toc_print(); |
---|
97 | |
---|
98 | <span class="comment">//Print the result of the processing:</span> |
---|
99 | cout << <span class="stringliteral">"The sum of all integers from 0 to "</span> << N - 1 << <span class="stringliteral">" equals "</span> << sum << endl; |
---|
100 | |
---|
101 | <span class="comment">//Exit program:</span> |
---|
102 | <span class="keywordflow">return</span> 0; |
---|
103 | |
---|
104 | } |
---|
105 | </pre></div><p>When you run this program, the output will look something like this:</p> |
---|
106 | <div class="fragment"><pre class="fragment">Elapsed time = 0.000797055 seconds |
---|
107 | The sum of all integers from 0 to 999999 equals 1783293664 |
---|
108 | </pre></div> </div> |
---|
109 | <hr size="1"/><address style="text-align: right;"><small>Generated on Tue Sep 15 23:42:47 2009 for mixpp by |
---|
110 | <a href="http://www.doxygen.org/index.html"> |
---|
111 | <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address> |
---|
112 | </body> |
---|
113 | </html> |
---|