CppAD: A C++ Algorithmic Differentiation Package  20130918
microsoft_timer.cpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 /* --------------------------------------------------------------------------
00003 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
00004 
00005 CppAD is distributed under multiple licenses. This distribution is under
00006 the terms of the 
00007                     Eclipse Public License Version 1.0.
00008 
00009 A copy of this license is included in the COPYING file of this distribution.
00010 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00011 -------------------------------------------------------------------------- */
00012 /*
00013 $begin microsoft_timer$$
00014 $spell
00015      Microsoft
00016      cpp
00017 $$
00018 
00019 $section Microsoft Version of Elapsed Number of Seconds$$
00020 
00021 
00022 $head Syntax$$
00023 $icode%s% = microsoft_timer()%$$
00024 
00025 $head Purpose$$
00026 This routine is accurate to within .02 seconds
00027 (see $cref elapsed_seconds$$ which uses this routine when 
00028 the preprocessor symbol $code _MSC_VER$$ is defined).
00029 It does not necessary work for time intervals that are greater than a day.
00030 It uses $code ::GetSystemTime$$ for timing.
00031 
00032 $head s$$
00033 is a $code double$$ equal to the 
00034 number of seconds since the first call to $code microsoft_timer$$.
00035 
00036 $head Linking$$
00037 The source code for this routine is located in 
00038 $code speed/microsoft_timer.cpp$$.
00039 The preprocessor symbol $code _MSC_VER$$ must
00040 be defined, or this routine is not compiled.
00041 
00042 $end
00043 -----------------------------------------------------------------------
00044 */
00045 # if _MSC_VER
00046 # include <windows.h>
00047 # include <cassert>
00048 
00049 // Note that the doxygen for this routine does not get generated because
00050 // _MSC_VER is not defined during generation. In general, it is a problem
00051 // that not all preprocessor options get documented.
00052 /*!
00053 \{
00054 \file microsoft_timer.cpp
00055 \brief Microsoft version of elapsed_seconds.
00056 */
00057 
00058 /*!
00059 Microsoft version of elapsed number of seconds since frist call.
00060 
00061 \copydetails elapsed_seconds
00062 */
00063 double microsoft_timer(void)
00064 {    static bool       first_  = true;
00065      static SYSTEMTIME st_;
00066      SYSTEMTIME st;
00067 
00068      if( first_ )
00069      {    ::GetSystemTime(&st_);
00070           first_ = false;
00071           return 0.;
00072      }
00073      ::GetSystemTime(&st);
00074 
00075      double hour   = double(st.wHour)         - double(st_.wHour);
00076      double minute = double(st.wMinute)       - double(st_.wMinute);
00077      double second = double(st.wSecond)       - double(st_.wSecond);
00078      double milli  = double(st.wMilliseconds) - double(st_.wMilliseconds);
00079 
00080      double diff   = 1e-3*milli + second + 60.*minute + 3600.*hour;
00081      if( diff < 0. )
00082           diff += 3600.*24.;
00083      assert( 0 <= diff && diff < 3600.*24. );
00084 
00085      return diff;
00086 }
00087 
00088 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines