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 #include "Teuchos_GlobalMPISession.hpp"
00031 #include "Teuchos_StandardCatchMacros.hpp"
00032 
00033 int main(int argc, char* argv[])
00034 {
00035 
00036   using std::cout;
00037   using std::endl;
00038   using StopWatchPack::stopwatch;
00039   
00040   bool success = true;
00041 
00042   Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00043 
00044   try {
00045     
00046     stopwatch timer;
00047     
00048     // Finding min resolution.
00049     double min_resolution = 0.0; // in seconds
00050     int total_num_calls   = 0;
00051     {
00052       cout  << "\n*** Measuring miminum resolution.\n";
00053       timer.start();
00054       double last_time = timer.read();
00055       const int max_num_samples = 20;
00056       int num_samples = 0;
00057       int num_calls = 0;
00058       while( num_samples < max_num_samples ) {
00059         double time = timer.read();
00060         num_calls++;
00061         if( time - last_time > 0.0 ) {
00062           cout  << "time_diff = " << time - last_time
00063                 << ", num_calls = " << num_calls << endl;
00064           min_resolution += time - last_time;
00065           ++total_num_calls;
00066           last_time = time;
00067           num_calls = 0;
00068           num_samples++;
00069         }
00070       }
00071       min_resolution /= total_num_calls;
00072     }
00073     
00074     std::cerr << "Minimum stopwatch resolution = " << min_resolution << " sec\n";
00075     
00076     // Finding increasing resolution.
00077     {
00078       cout  << "\n*** Measuring increasing resolution.\n";
00079       timer.start();
00080       double start_time = timer.read(), last_time = start_time;
00081       const int max_num_samples = 20;
00082       int num_samples = 0;
00083       int num_calls = 0;
00084       while( num_samples < max_num_samples ) {
00085         double time = timer.read();
00086         num_calls++;
00087         if( time - last_time > 0.0 ) {
00088           cout  << "time = " << time - start_time
00089                 << ", num_calls = " << num_calls << endl;
00090           last_time = time;
00091           num_calls = 0;
00092           num_samples++;
00093         }
00094       }
00095     }
00096 
00097   } // end try
00098   TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
00099   
00100   if(success)
00101     cout << "\nEnd Result: TEST PASSED" << std::endl;
00102   
00103   return 0;
00104   
00105 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:11:01 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3