Rcpp Version 1.0.9
Timer.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2 //
3 // Timer.h: Rcpp R/C++ interface class library -- simple timer class
4 //
5 // Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23 // Simple timer class based on on ideas in atimer.h / atimer.cxx found a few years ago at
24 // http://www.cs.uiowa.edu/~sriram/30/fall03/
25 // and attributed to Amir Elaguizy while under GPL
26 // but converted to using gettimeofday/GetSystemTime instead
27 
28 #ifndef TIMER_H
29 #define TIMER_H
30 
31 class Timer {
32 public:
33  Timer() : sys_time("Sys.time") { Reset(); }
35  void Stop() {
37  elapsed = end_t - start_t; // Calculate elapsed time in seconds
38  cumul += elapsed;
39  }
40  void Reset() { end_t = start_t = elapsed = cumul = 0.0; }
41  double ElapsedTime() { return elapsed; }
42  double CumulativeTime() { return cumul; }
43 
44 
45 private:
48 
49  double getFractionalSeconds(void) {
50  return as<double>( sys_time() ) ;
51  }
52 };
53 
54 #endif
55 
Definition: Timer.h:31
double ElapsedTime()
Definition: Timer.h:41
void Start()
Definition: Timer.h:34
double start_t
Definition: Timer.h:47
Timer()
Definition: Timer.h:33
void Stop()
Definition: Timer.h:35
double CumulativeTime()
Definition: Timer.h:42
double cumul
Definition: Timer.h:47
double end_t
Definition: Timer.h:47
double getFractionalSeconds(void)
Definition: Timer.h:49
void Reset()
Definition: Timer.h:40
double elapsed
Definition: Timer.h:47
Function sys_time
Definition: Timer.h:46
Function_Impl< PreserveStorage > Function
Definition: Function.h:122