Beispiel #1
0
    static void estimate_benchmark_params(
        IBenchmarkCase*         benchmark,
        StopwatchType&          stopwatch,
        BenchmarkParams&        params)
    {
        const size_t InitialIterationCount = 1;
        const size_t InitialMeasurementCount = 3;
        const double TargetMeasurementTime = 1.0e-3;    // seconds
        const double TargetTotalTime = 0.5;             // seconds

        // Measure the runtime for the initial number of iterations.
        const double time =
            measure_runtime(
                benchmark,
                stopwatch,
                BenchmarkSuite::Impl::measure_runtime_seconds,
                InitialIterationCount,
                InitialMeasurementCount);

        // Compute the number of iterations.
        const double iteration_time = time / InitialIterationCount;
        params.m_iteration_count = max<size_t>(1, static_cast<size_t>(TargetMeasurementTime / iteration_time));

        // Compute the number of measurements.
        const double measurement_time = iteration_time * params.m_iteration_count;
        params.m_measurement_count = max<size_t>(1, static_cast<size_t>(TargetTotalTime / measurement_time));
    }
Beispiel #2
0
 // Measure and return the overhead (in ticks) of running an empty benchmark case.
 static double measure_call_overhead_ticks(
     StopwatchType&          stopwatch,
     const size_t            measurement_count)
 {
     unique_ptr<IBenchmarkCase> empty_case(new EmptyBenchmarkCase());
     return
         measure_runtime(
             empty_case.get(),
             stopwatch,
             BenchmarkSuite::Impl::measure_runtime_ticks,
             measurement_count);
 }
Beispiel #3
0
 static double measure_iteration_runtime(
     IBenchmarkCase*         benchmark,
     StopwatchType&          stopwatch,
     const BenchmarkParams&  params)
 {
     return
         measure_runtime(
             benchmark,
             stopwatch,
             BenchmarkSuite::Impl::measure_runtime_ticks,
             params.m_iteration_count,
             params.m_measurement_count)
         / params.m_iteration_count;
 }
Beispiel #4
0
    static size_t compute_measurement_count(
        IBenchmarkCase*         benchmark,
        StopwatchType&          stopwatch)
    {
        // Measure the runtime using a very small number of measurements. Not accurate.
        const size_t InitialMeasurementCount = 10;
        const double measurement_time =
            measure_runtime(
                benchmark,
                stopwatch,
                BenchmarkSuite::Impl::measure_runtime_seconds,
                InitialMeasurementCount);

        // Compute the number of measurements to get an accurate runtime measure.
        const size_t MaxMeasurementCount = 1000000;
        const double MaxTargetTotalTime = 0.1;          // seconds
        return
            static_cast<size_t>(ceil(
                min(MaxMeasurementCount * measurement_time, MaxTargetTotalTime) / measurement_time));
    }