Returns Elapsed Number of Seconds
Keywords: returns elapsed number seconds syntax purpose s source code

| Prev | Next |  |  |  |  |  | elapsed_seconds_c |

Returns Elapsed Number of Seconds
Syntax
`s = elapsed_seconds()`
Purpose
This routine is accurate to within .02 seconds It does not necessary work for time intervals that are greater than a day.
s
is a `double` equal to the number of seconds since the first call to `elapsed_seconds`.
Source Code `

    # if _MSC_VER
    // ---------------------------------------------------------------------------
    // Microsoft version of timer
    # include <windows.h>
    # include <cassert>
    double elapsed_seconds(void)
    {    static bool       first_  = true;
         static SYSTEMTIME st_;
         double hour, minute, second, milli, diff;
         SYSTEMTIME st;

         if( first_ )
         {    GetSystemTime(&st_);
              first_ = false;
              return 0.;
         }
         GetSystemTime(&st);

         hour   = (double) st.wHour         - (double) st_.wHour;
         minute = (double) st.wMinute       - (double) st_.wMinute;
         second = (double) st.wSecond       - (double) st_.wSecond;
         milli  = (double) st.wMilliseconds - (double) st_.wMilliseconds;

         diff   = 1e-3*milli + second + 60.*minute + 3600.*hour;
         if( diff < 0. )
              diff += 3600.*24.;
         assert( 0 <= diff && diff < 3600.*24. );

         return diff;
    }
    # else
    // ---------------------------------------------------------------------------
    // Unix version of timer
    # include <sys/time.h>
    double elapsed_seconds(void)
    {    double sec, usec, diff;

         static bool first_ = true;
         static struct timeval tv_first;
         struct timeval        tv;
         if( first_ )
         {    gettimeofday(&tv_first, NULL);
              first_ = false;
              return 0.;
         }
         gettimeofday(&tv, NULL);
         assert( tv.tv_sec >= tv_first.tv_sec );

         sec  = (double)(tv.tv_sec -  tv_first.tv_sec);
         usec = (double)tv.tv_usec - (double)tv_first.tv_usec;
         diff = sec + 1e-6*usec;

         return diff;
    }
    # endif

`

Input File: compare_c/det_by_minor.c