StopWatchPack_stopwatch.cpp

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 <iostream>
00030 //#include <iosfwd>
00031 
00032 #include "StopWatchPack_stopwatch.hpp"
00033 #include "Teuchos_Time.hpp"
00034 
00035 double StopWatchPack::seconds(void)
00036 {
00037   return Teuchos::Time::wallTime();
00038 }
00039 
00040 /*
00041 
00042 #ifndef _INTEL_CXX
00043 
00044 // Implementation using C standard library.
00045 // In MS VC++ 6.0 the precision is only about 0.05 sec.
00046 
00047 #include <time.h>
00048 
00049 double StopWatchPack::seconds(void)
00050 {
00051     static const double secs_per_tick = ((double)1.0) / CLOCKS_PER_SEC;
00052   const clock_t ticks = clock();
00053   const double sec = ( (double) ticks ) * secs_per_tick;
00054   //std::cout << "ticks = " << ticks << ", sec = " << sec << std::endl;
00055     return sec;
00056 }
00057 
00058 #else // _INTEL_CXX implementation
00059 
00060 // Windows implementation.
00061 
00062 #define WIN32_LEAN_AND_MEAN
00063 #include <windows.h>
00064 #include <assert.h>
00065 
00066 namespace {
00067 
00068 bool seconds_initialized = false;
00069 LARGE_INTEGER start_count, count_freq;  // counts per sec.
00070 
00071 inline void seconds_initialize() {
00072   if( seconds_initialized ) return;
00073   // Figure out how often the performance counter increments
00074   ::QueryPerformanceFrequency( &count_freq );
00075   // Set this thread's priority as high as reasonably possible to prevent
00076     // timeslice interruptions
00077     ::SetThreadPriority( ::GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
00078   // Get the first count.
00079   TEST_FOR_EXCEPT( !(  QueryPerformanceCounter( &start_count )  ) );
00080   seconds_initialized = true;
00081 }
00082 
00083 } // end namespace
00084 
00085 double StopWatchPack::seconds(void)
00086 {
00087   seconds_initialize();
00088   LARGE_INTEGER count;
00089   QueryPerformanceCounter( &count );
00090   // "QuadPart" is a 64 bit integer (__int64).  VC++ supports them!
00091   const double
00092     sec = (double)( count.QuadPart - start_count.QuadPart ) / count_freq.QuadPart;
00093   //std::cout << "ticks = " << ticks << ", sec = " << sec << std::endl;
00094     return sec;
00095 }
00096 
00097 #endif  // _INTEL_CXX
00098 
00099 */

Generated on Wed May 12 21:50:25 2010 for MoochoPack: Miscellaneous Utilities for MOOCHO by  doxygen 1.4.7