StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
timerTest.cc
1 #include "StTimer.hh"
2 #include <time.h>
3 #include <Stiostream.h>
4 #include <math.h>
5 
6 
7 int main()
8 {
9  StTimer timer, totalTimer;
10 
11  totalTimer.start();
12  timer.start();
13 
14  // Spend 5 busy sec.
15  time_t begin = time(0);
16  time_t now = begin;
17  while (now - begin < 5) now = time(0);
18 
19  timer.stop();
20 
21  cout << "Test 1:" << endl;
22  cout << "This test should require less than 5 sec CPU time. \n"
23  << "The exact amount depends strongly on the system." << endl;
24  cout << "The measured elapsed CPU time is: "
25  << timer.elapsedTime() << " sec\n" << endl;
26 
27  timer.reset();
28  timer.start();
29 
30  const size_t NumSqrt = 1000000;
31  double x;
32  for (int i=0; i<NumSqrt; i++) x = ::sqrt(double(i));
33 
34  timer.stop();
35 
36  cout << "Test 2:" << endl;
37  cout << "The CPU time to calculate " << NumSqrt
38  << " square roots is: "
39  << timer.elapsedTime() << " sec\n" << endl;
40 
41  cout << "The total amount of CPU seconds used \n"
42  << "to execute this program is: ";
43  totalTimer.stop();
44  cout << totalTimer.elapsedTime() << " sec." << endl;
45 
46  return 0;
47 }