mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-16 10:42:25 +01:00
Slight improvement to computing clock resolution in benchmarking
This commit is contained in:
parent
22e6490325
commit
7af96bbb22
@ -27,15 +27,17 @@ namespace Catch {
|
|||||||
namespace Detail {
|
namespace Detail {
|
||||||
template <typename Clock>
|
template <typename Clock>
|
||||||
std::vector<double> resolution(int k) {
|
std::vector<double> resolution(int k) {
|
||||||
std::vector<TimePoint<Clock>> times;
|
const size_t points = static_cast<size_t>( k + 1 );
|
||||||
times.reserve(static_cast<size_t>(k + 1));
|
// To avoid overhead from the branch inside vector::push_back,
|
||||||
for ( int i = 0; i < k + 1; ++i ) {
|
// we allocate them all and then overwrite.
|
||||||
times.push_back( Clock::now() );
|
std::vector<TimePoint<Clock>> times(points);
|
||||||
|
for ( auto& time : times ) {
|
||||||
|
time = Clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<double> deltas;
|
std::vector<double> deltas;
|
||||||
deltas.reserve(static_cast<size_t>(k));
|
deltas.reserve(static_cast<size_t>(k));
|
||||||
for ( size_t idx = 1; idx < times.size(); ++idx ) {
|
for ( size_t idx = 1; idx < points; ++idx ) {
|
||||||
deltas.push_back( static_cast<double>(
|
deltas.push_back( static_cast<double>(
|
||||||
( times[idx] - times[idx - 1] ).count() ) );
|
( times[idx] - times[idx - 1] ).count() ) );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user