00001 #include "StTimer.hh"
00002 #include <time.h>
00003 #include <Stiostream.h>
00004 #include <math.h>
00005
00006
00007 int main()
00008 {
00009 StTimer timer, totalTimer;
00010
00011 totalTimer.start();
00012 timer.start();
00013
00014
00015 time_t begin = time(0);
00016 time_t now = begin;
00017 while (now - begin < 5) now = time(0);
00018
00019 timer.stop();
00020
00021 cout << "Test 1:" << endl;
00022 cout << "This test should require less than 5 sec CPU time. \n"
00023 << "The exact amount depends strongly on the system." << endl;
00024 cout << "The measured elapsed CPU time is: "
00025 << timer.elapsedTime() << " sec\n" << endl;
00026
00027 timer.reset();
00028 timer.start();
00029
00030 const size_t NumSqrt = 1000000;
00031 double x;
00032 for (int i=0; i<NumSqrt; i++) x = ::sqrt(double(i));
00033
00034 timer.stop();
00035
00036 cout << "Test 2:" << endl;
00037 cout << "The CPU time to calculate " << NumSqrt
00038 << " square roots is: "
00039 << timer.elapsedTime() << " sec\n" << endl;
00040
00041 cout << "The total amount of CPU seconds used \n"
00042 << "to execute this program is: ";
00043 totalTimer.stop();
00044 cout << totalTimer.elapsedTime() << " sec." << endl;
00045
00046 return 0;
00047 }