Skip to content

Commit bddd19c

Browse files
committed
manual merge after #158
simple update to inst/NEWS.Rd
2 parents e7af4a9 + 9751e6e commit bddd19c

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

inst/NEWS.Rd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
\item The deprecation of \code{RCPP_FUNCTION_*} which was announced with
1010
release 0.10.5 last year is proceeding as planned, and the file
1111
\code{macros/preprocessor_generated.h} has been removed.
12-
\item The \code{Timer} class has a new method providing a set of timers
13-
which is useful in multhithreaded contexts.
12+
\item \code{Timer} no longer records time between steps, but times from
13+
the origin. It also gains a \code{get_timers(int)} methods that
14+
creates a vector of \code{Timer} that have the same origin. This is modelled
15+
on the \code{Rcpp11} implementation and is more useful for situations where
16+
we use timers in several threads. \code{Timer} also gains a constructor
17+
taking a \code{nanotime_t} to use as its origin, and a \code{origin} method.
18+
This can be useful for situations where the number of threads is not known
19+
in advance but we still want to track what goes on in each thread.
1420
}
1521
\item Changes in Rcpp Sugar:
1622
\itemize{

inst/include/Rcpp/Benchmark/Timer.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ namespace Rcpp{
103103
class Timer {
104104
public:
105105
Timer() : data(), start_time( get_nanotime() ){}
106+
Timer(nanotime_t start_time_) : data(), start_time(start_time_){}
106107

107108
void step( const std::string& name){
108-
nanotime_t now = get_nanotime();
109-
data.push_back(std::make_pair(name, now - start_time));
110-
start_time = get_nanotime();
109+
data.push_back(std::make_pair(name, now()));
111110
}
112111

113112
operator SEXP() const {
@@ -116,7 +115,7 @@ namespace Rcpp{
116115
CharacterVector names(n);
117116
for (size_t i=0; i<n; i++) {
118117
names[i] = data[i].first;
119-
out[i] = data[i].second;
118+
out[i] = data[i].second - start_time ;
120119
}
121120
out.attr("names") = names;
122121
return out;
@@ -125,13 +124,21 @@ namespace Rcpp{
125124
static std::vector<Timer> get_timers(int n){
126125
return std::vector<Timer>( n, Timer() ) ;
127126
}
127+
128+
inline nanotime_t now() const {
129+
return get_nanotime() ;
130+
}
131+
132+
inline nanotime_t origin() const {
133+
return start_time ;
134+
}
128135

129136
private:
130137
typedef std::pair<std::string,nanotime_t> Step;
131138
typedef std::vector<Step> Steps;
132139

133140
Steps data;
134-
nanotime_t start_time;
141+
const nanotime_t start_time;
135142
};
136143

137144
}

0 commit comments

Comments
 (0)