File tree 1 file changed +7
-5
lines changed
src/catch2/benchmark/detail
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -27,15 +27,17 @@ namespace Catch {
27
27
namespace Detail {
28
28
template <typename Clock>
29
29
std::vector<double > resolution (int k) {
30
- std::vector<TimePoint<Clock>> times;
31
- times.reserve (static_cast <size_t >(k + 1 ));
32
- for ( int i = 0 ; i < k + 1 ; ++i ) {
33
- times.push_back ( Clock::now () );
30
+ const size_t points = static_cast <size_t >( k + 1 );
31
+ // To avoid overhead from the branch inside vector::push_back,
32
+ // we allocate them all and then overwrite.
33
+ std::vector<TimePoint<Clock>> times (points);
34
+ for ( auto & time : times ) {
35
+ time = Clock::now ();
34
36
}
35
37
36
38
std::vector<double > deltas;
37
39
deltas.reserve (static_cast <size_t >(k));
38
- for ( size_t idx = 1 ; idx < times. size () ; ++idx ) {
40
+ for ( size_t idx = 1 ; idx < points ; ++idx ) {
39
41
deltas.push_back ( static_cast <double >(
40
42
( times[idx] - times[idx - 1 ] ).count () ) );
41
43
}
You can’t perform that action at this time.
0 commit comments