/usr/include/cppad/elapsed_seconds.hpp is in cppad 2014.00.00.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | /* $Id: elapsed_seconds.hpp 2910 2013-10-07 13:27:58Z bradbell $ */
# ifndef CPPAD_ELAPSED_SECONDS_INCLUDED
# define CPPAD_ELAPSED_SECONDS_INCLUDED
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
GNU General Public License Version 3.
A copy of this license is included in the COPYING file of this distribution.
Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
-------------------------------------------------------------------------- */
/*
$begin elapsed_seconds$$
$spell
Microsoft
gettimeofday
std
$$
$section Returns Elapsed Number of Seconds$$
$index elapsed_seconds$$
$index seconds, time$$
$index time, seconds$$
$head Syntax$$
$icode%s% = elapsed_seconds()%$$
$head Purpose$$
This routine is accurate to within .02 seconds
(see $cref elapsed_seconds.cpp$$).
It does not necessary work for time intervals that are greater than a day.
$list number$$
If running under the Microsoft compiler, it uses
$code ::GetSystemTime$$ for timing.
$lnext
Otherwise, if $code gettimeofday$$ is available, it is used.
$lnext
Otherwise, $code std::clock()$$ is used.
$lend
$head s$$
is a $code double$$ equal to the
number of seconds since the first call to $code elapsed_seconds$$.
$head Microsoft Systems$$
It you are using the Microsoft C++ compiler,
you will need to link in the external routine
called $cref microsoft_timer$$.
$children%
speed/example/elapsed_seconds.cpp
%$$
$head Example$$
The routine $cref elapsed_seconds.cpp$$ is
an example and test of this routine.
$end
-----------------------------------------------------------------------
*/
// For some unknown reason under Fedora (which needs to be understood),
// if you move this include for cppad_assert.hpp below include for define.hpp,
// cd work/speed/example
// make test.sh
// fails with the error message 'gettimeofday' not defined.
# include <cppad/local/cppad_assert.hpp>
# ifdef _MSC_VER
extern double microsoft_timer(void);
# elif CPPAD_HAS_GETTIMEOFDAY
# include <sys/time.h>
# else
# include <ctime>
# endif
// define CPPAD_NULL
# include <cppad/local/define.hpp>
// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL
# include <cppad/thread_alloc.hpp>
namespace CppAD { // BEGIN_CPPAD_NAMESPACE
/*!
\defgroup elapsed_seconds_hpp elapsed_seconds.hpp
\{
\file elapsed_seconds.hpp
\brief Function that returns the elapsed seconds from first call.
*/
/*!
Returns the elapsed number since the first call to this function.
This routine tries is accurate to within .02 seconds.
It does not necessary work for time intervals that are less than a day.
\li
If running under the Microsoft system, it uses \c ::%GetSystemTime for timing.
\li
Otherwise, if \c gettimeofday is available, it is used.
\li
Otherwise, \c std::clock() is used.
\return
The number of seconds since the first call to \c elapsed_seconds.
*/
inline double elapsed_seconds(void)
# ifdef _MSC_VER
{ return microsoft_timer(); }
# elif CPPAD_HAS_GETTIMEOFDAY
{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL;
static bool first_ = true;
static struct timeval tv_;
struct timeval tv;
if( first_ )
{ gettimeofday(&tv_, CPPAD_NULL);
first_ = false;
return 0.;
}
gettimeofday(&tv, CPPAD_NULL);
assert( tv.tv_sec >= tv_.tv_sec );
double sec = double(tv.tv_sec - tv_.tv_sec);
double usec = double(tv.tv_usec) - double(tv_.tv_usec);
double diff = sec + 1e-6*usec;
return diff;
}
# else
{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL;
static bool first_ = true;
static double tic_;
double tic;
if( first_ )
{ tic_ = double(std::clock());
first_ = false;
return 0.;
}
tic = double( std::clock() );
double diff = (tic - tic_) / double(CLOCKS_PER_SEC);
return diff;
}
# endif
/*! \} */
} // END_CPPAD_NAMESPACE
# endif
|