1 /*
2  *  Created by Phil on 04/07/2017.
3  *  Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 
9 #include "catch_benchmark.h"
10 #include "catch_capture.hpp"
11 #include "catch_interfaces_reporter.h"
12 #include "catch_context.h"
13 
14 namespace Catch {
15 
getResolution()16     auto BenchmarkLooper::getResolution() -> uint64_t {
17         return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple();
18     }
19 
reportStart()20     void BenchmarkLooper::reportStart() {
21         getResultCapture().benchmarkStarting( { m_name } );
22     }
needsMoreIterations()23     auto BenchmarkLooper::needsMoreIterations() -> bool {
24         auto elapsed = m_timer.getElapsedNanoseconds();
25 
26         // Exponentially increasing iterations until we're confident in our timer resolution
27         if( elapsed < m_resolution ) {
28             m_iterationsToRun *= 10;
29             return true;
30         }
31 
32         getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } );
33         return false;
34     }
35 
36 } // end namespace Catch
37