|
1 |
| -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- |
| 1 | +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- |
2 | 2 | //
|
3 | 3 | // Timer.h: Rcpp R/C++ interface class library -- Rcpp benchmark utility
|
4 | 4 | //
|
5 |
| -// Copyright (C) 2012 - 2013 JJ Allaire, Dirk Eddelbuettel and Romain Francois |
| 5 | +// Copyright (C) 2012 - 2014 JJ Allaire, Dirk Eddelbuettel and Romain Francois |
6 | 6 | //
|
7 | 7 | // This file is part of Rcpp.
|
8 | 8 | //
|
@@ -106,34 +106,30 @@ namespace Rcpp{
|
106 | 106 | Timer() : data(), start_time( get_nanotime() ){}
|
107 | 107 |
|
108 | 108 | void step( const std::string& name){
|
109 |
| - nanotime_t now = get_nanotime() ; |
110 |
| - data.push_back( std::make_pair( name, now - start_time ) ) ; |
111 |
| - start_time = get_nanotime() ; |
| 109 | + nanotime_t now = get_nanotime(); |
| 110 | + data.push_back(std::make_pair(name, now - start_time)); |
| 111 | + start_time = get_nanotime(); |
112 | 112 | }
|
113 | 113 |
|
114 | 114 | operator SEXP() const {
|
115 |
| - NumericVector out( data.begin(), data.end(), get_second ) ; |
116 |
| - CharacterVector names( data.begin(), data.end(), get_first ) ; |
117 |
| - out.attr( "names" ) = names ; |
118 |
| - return out ; |
| 115 | + size_t n = data.size(); |
| 116 | + NumericVector out(n); |
| 117 | + CharacterVector names(n); |
| 118 | + for (size_t i=0; i<n; i++) { |
| 119 | + names[i] = data[i].first; |
| 120 | + out[i] = data[i].second; |
| 121 | + } |
| 122 | + out.attr("names") = names; |
| 123 | + return out; |
119 | 124 | }
|
120 | 125 |
|
121 | 126 | private:
|
122 |
| - |
123 |
| - inline std::string get_first( const std::pair<std::string,nanotime_t>& pair ){ |
124 |
| - return pair.first ; |
125 |
| - } |
126 |
| - inline double get_second( const std::pair<std::string,nanotime_t>& pair ){ |
127 |
| - return static_cast<double>(pair.second) ; |
128 |
| - } |
129 |
| - |
130 | 127 | typedef std::pair<std::string,nanotime_t> Step;
|
131 | 128 | typedef std::vector<Step> Steps;
|
132 | 129 |
|
133 |
| - Steps data ; |
134 |
| - nanotime_t start_time ; |
135 |
| - |
136 |
| - } ; |
| 130 | + Steps data; |
| 131 | + nanotime_t start_time; |
| 132 | + }; |
137 | 133 |
|
138 | 134 | }
|
139 | 135 |
|
|
0 commit comments