Prev Next elapsed_seconds_c

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@This is cppad-20221105 documentation. Here is a link to its current documentation .
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
# ifndef NOMINMAX
# define NOMINMAX  // so windows.h does not define min and max as macros
# endif
# 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: test_more/compare_c/det_by_minor.c