MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / Timer

Class Timer

inst/include/Rcpp/Benchmark/Timer.h:103–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101#endif
102
103 class Timer {
104 public:
105 Timer() : data(), start_time( get_nanotime() ){}
106 Timer(nanotime_t start_time_) : data(), start_time(start_time_){}
107
108 void step( const std::string& name){
109 data.push_back(std::make_pair(name, now()));
110 }
111
112 operator SEXP() const {
113 size_t n = data.size();
114 NumericVector out(n);
115 CharacterVector names(n);
116 for (size_t i=0; i<n; i++) {
117 names[i] = data[i].first;
118 out[i] = data[i].second - start_time ;
119 }
120 out.attr("names") = names;
121 return out;
122 }
123
124 static std::vector<Timer> get_timers(int n){
125 return std::vector<Timer>( n, Timer() ) ;
126 }
127
128 inline nanotime_t now() const {
129 return get_nanotime() ;
130 }
131
132 inline nanotime_t origin() const {
133 return start_time ;
134 }
135
136 private:
137 typedef std::pair<std::string,nanotime_t> Step;
138 typedef std::vector<Step> Steps;
139
140 Steps data;
141 const nanotime_t start_time;
142 };
143
144}
145

Callers 1

get_timersMethod · 0.70

Calls 2

attrMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected