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
(); }
34
void
Start
() {
start_t
=
getFractionalSeconds
() ; }
35
void
Stop
() {
36
end_t
=
getFractionalSeconds
();
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
:
46
Function
sys_time
;
47
double
start_t
,
end_t
,
elapsed
,
cumul
;
48
49
double
getFractionalSeconds
(
void
) {
50
return
as<double>(
sys_time
() ) ;
51
}
52
};
53
54
#endif
55
Timer
Definition:
Timer.h:31
Timer::ElapsedTime
double ElapsedTime()
Definition:
Timer.h:41
Timer::Start
void Start()
Definition:
Timer.h:34
Timer::start_t
double start_t
Definition:
Timer.h:47
Timer::Timer
Timer()
Definition:
Timer.h:33
Timer::Stop
void Stop()
Definition:
Timer.h:35
Timer::CumulativeTime
double CumulativeTime()
Definition:
Timer.h:42
Timer::cumul
double cumul
Definition:
Timer.h:47
Timer::end_t
double end_t
Definition:
Timer.h:47
Timer::getFractionalSeconds
double getFractionalSeconds(void)
Definition:
Timer.h:49
Timer::Reset
void Reset()
Definition:
Timer.h:40
Timer::elapsed
double elapsed
Definition:
Timer.h:47
Timer::sys_time
Function sys_time
Definition:
Timer.h:46
Rcpp::Function
Function_Impl< PreserveStorage > Function
Definition:
Function.h:122
inst
examples
SugarPerformance
Timer.h
Generated on Sat Jul 9 2022 09:14:52 for Rcpp Version 1.0.9 by
1.9.1