22 #ifndef RCPP_BENCHMARH_TIMER_H
23 #define RCPP_BENCHMARH_TIMER_H
30 #include <Rinternals.h>
33 #define WIN32_LEAN_AND_MEAN
35 #elif defined(__APPLE__)
36 #include <mach/mach_time.h>
37 #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__GLIBC__) || defined(__GNU__) || defined(__CYGWIN__)
39 #elif defined(sun) || defined(__sun) || defined(_AIX)
42 #error "Rcpp::Timer not supported by your OS."
52 LARGE_INTEGER time_var, frequency;
53 QueryPerformanceCounter(&time_var);
54 QueryPerformanceFrequency(&frequency);
57 return 1.0e9 * time_var.QuadPart / frequency.QuadPart;
60 #elif defined(__APPLE__)
64 mach_timebase_info_data_t info;
66 time = mach_absolute_time();
67 mach_timebase_info(&info);
70 return time * (info.numer / info.denom);
73 #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__GLIBC__) || defined(__GNU__) || defined(__CYGWIN__)
78 struct timespec time_var;
85 clock_gettime(CLOCK_REALTIME, &time_var);
91 return (nanoseconds_in_second * sec) + nsec;
94 #elif defined(sun) || defined(__sun) || defined(_AIX)
108 void step(
const std::string& name){
109 data.push_back(std::make_pair(name,
now()));
112 operator SEXP()
const {
113 size_t n =
data.size();
116 for (
size_t i=0; i<n; i++) {
117 names[i] =
data[i].first;
120 out.
attr(
"names") = names;
125 return std::vector<Timer>( n,
Timer() ) ;
129 return get_nanotime() ;
137 typedef std::pair<std::string,nanotime_t>
Step;
AttributeProxy attr(const std::string &name)
Timer(nanotime_t start_time_)
std::vector< Step > Steps
const nanotime_t start_time
nanotime_t origin() const
void step(const std::string &name)
static std::vector< Timer > get_timers(int n)
std::pair< std::string, nanotime_t > Step