TestStopWatchMain.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include "StopWatchPack_stopwatch.hpp"
00030 
00031 int main() {
00032   using std::cout;
00033   using std::endl;
00034   using StopWatchPack::stopwatch;
00035 
00036   stopwatch timer;
00037 
00038   // Finding min resolution.
00039   double min_resolution = 0.0; // in seconds
00040   int total_num_calls   = 0;
00041   {
00042     cout  << "\n*** Measuring miminum resolution.\n";
00043     timer.start();
00044     double last_time = timer.read();
00045     const int max_num_samples = 20;
00046     int num_samples = 0;
00047     int num_calls = 0;
00048     while( num_samples < max_num_samples ) {
00049       double time = timer.read();
00050       num_calls++;
00051       if( time - last_time > 0.0 ) {
00052         cout  << "time_diff = " << time - last_time
00053             << ", num_calls = " << num_calls << endl;
00054         min_resolution += time - last_time;
00055         ++total_num_calls;
00056         last_time = time;
00057         num_calls = 0;
00058         num_samples++;
00059       }
00060     }
00061     min_resolution /= total_num_calls;
00062   }
00063 
00064   std::cerr << "Minimum stopwatch resolution = " << min_resolution << " sec\n";
00065 
00066   // Finding increasing resolution.
00067   {
00068     cout  << "\n*** Measuring increasing resolution.\n";
00069     timer.start();
00070     double start_time = timer.read(), last_time = start_time;
00071     const int max_num_samples = 20;
00072     int num_samples = 0;
00073     int num_calls = 0;
00074     while( num_samples < max_num_samples ) {
00075       double time = timer.read();
00076       num_calls++;
00077       if( time - last_time > 0.0 ) {
00078         cout  << "time = " << time - start_time
00079             << ", num_calls = " << num_calls << endl;
00080         last_time = time;
00081         num_calls = 0;
00082         num_samples++;
00083       }
00084     }
00085   }
00086 
00087   return 0;
00088 }

Generated on Tue Oct 20 12:51:49 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7