-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb9d8ea
commit 8a74859
Showing
179 changed files
with
15,749 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
thirdparty/catch2/src/main/native/include/catch2/benchmark/catch_benchmark.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
|
||
// Copyright Catch2 Authors | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.txt or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
// SPDX-License-Identifier: BSL-1.0 | ||
// Adapted from donated nonius code. | ||
|
||
#ifndef CATCH_BENCHMARK_HPP_INCLUDED | ||
#define CATCH_BENCHMARK_HPP_INCLUDED | ||
|
||
#include <catch2/catch_user_config.hpp> | ||
#include <catch2/internal/catch_compiler_capabilities.hpp> | ||
#include <catch2/internal/catch_context.hpp> | ||
#include <catch2/internal/catch_move_and_forward.hpp> | ||
#include <catch2/internal/catch_test_failure_exception.hpp> | ||
#include <catch2/internal/catch_unique_name.hpp> | ||
#include <catch2/interfaces/catch_interfaces_capture.hpp> | ||
#include <catch2/interfaces/catch_interfaces_config.hpp> | ||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp> | ||
#include <catch2/benchmark/detail/catch_benchmark_stats.hpp> | ||
#include <catch2/benchmark/catch_clock.hpp> | ||
#include <catch2/benchmark/catch_environment.hpp> | ||
#include <catch2/benchmark/catch_execution_plan.hpp> | ||
#include <catch2/benchmark/detail/catch_estimate_clock.hpp> | ||
#include <catch2/benchmark/detail/catch_analyse.hpp> | ||
#include <catch2/benchmark/detail/catch_benchmark_function.hpp> | ||
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp> | ||
|
||
#include <algorithm> | ||
#include <chrono> | ||
#include <exception> | ||
#include <string> | ||
#include <cmath> | ||
|
||
namespace Catch { | ||
namespace Benchmark { | ||
struct Benchmark { | ||
Benchmark(std::string&& benchmarkName) | ||
: name(CATCH_MOVE(benchmarkName)) {} | ||
|
||
template <class FUN> | ||
Benchmark(std::string&& benchmarkName , FUN &&func) | ||
: fun(CATCH_MOVE(func)), name(CATCH_MOVE(benchmarkName)) {} | ||
|
||
template <typename Clock> | ||
ExecutionPlan prepare(const IConfig &cfg, Environment env) { | ||
auto min_time = env.clock_resolution.mean * Detail::minimum_ticks; | ||
auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime())); | ||
auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<IDuration>(run_time), 1, fun); | ||
int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed)); | ||
return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), CATCH_MOVE(fun), std::chrono::duration_cast<FDuration>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations }; | ||
} | ||
|
||
template <typename Clock = default_clock> | ||
void run() { | ||
static_assert( Clock::is_steady, | ||
"Benchmarking clock should be steady" ); | ||
auto const* cfg = getCurrentContext().getConfig(); | ||
|
||
auto env = Detail::measure_environment<Clock>(); | ||
|
||
getResultCapture().benchmarkPreparing(name); | ||
CATCH_TRY{ | ||
auto plan = user_code([&] { | ||
return prepare<Clock>(*cfg, env); | ||
}); | ||
|
||
BenchmarkInfo info { | ||
CATCH_MOVE(name), | ||
plan.estimated_duration.count(), | ||
plan.iterations_per_sample, | ||
cfg->benchmarkSamples(), | ||
cfg->benchmarkResamples(), | ||
env.clock_resolution.mean.count(), | ||
env.clock_cost.mean.count() | ||
}; | ||
|
||
getResultCapture().benchmarkStarting(info); | ||
|
||
auto samples = user_code([&] { | ||
return plan.template run<Clock>(*cfg, env); | ||
}); | ||
|
||
auto analysis = Detail::analyse(*cfg, samples.data(), samples.data() + samples.size()); | ||
BenchmarkStats<> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance }; | ||
getResultCapture().benchmarkEnded(stats); | ||
} CATCH_CATCH_ANON (TestFailureException const&) { | ||
getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr); | ||
} CATCH_CATCH_ALL{ | ||
getResultCapture().benchmarkFailed(translateActiveException()); | ||
// We let the exception go further up so that the | ||
// test case is marked as failed. | ||
std::rethrow_exception(std::current_exception()); | ||
} | ||
} | ||
|
||
// sets lambda to be used in fun *and* executes benchmark! | ||
template <typename Fun, std::enable_if_t<!Detail::is_related<Fun, Benchmark>::value, int> = 0> | ||
Benchmark & operator=(Fun func) { | ||
auto const* cfg = getCurrentContext().getConfig(); | ||
if (!cfg->skipBenchmarks()) { | ||
fun = Detail::BenchmarkFunction(func); | ||
run(); | ||
} | ||
return *this; | ||
} | ||
|
||
explicit operator bool() { | ||
return true; | ||
} | ||
|
||
private: | ||
Detail::BenchmarkFunction fun; | ||
std::string name; | ||
}; | ||
} | ||
} // namespace Catch | ||
|
||
#define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1 | ||
#define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2 | ||
|
||
#define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\ | ||
if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ | ||
BenchmarkName = [&](int benchmarkIndex) | ||
|
||
#define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\ | ||
if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ | ||
BenchmarkName = [&] | ||
|
||
#if defined(CATCH_CONFIG_PREFIX_ALL) | ||
|
||
#define CATCH_BENCHMARK(...) \ | ||
INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) | ||
#define CATCH_BENCHMARK_ADVANCED(name) \ | ||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name) | ||
|
||
#else | ||
|
||
#define BENCHMARK(...) \ | ||
INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) | ||
#define BENCHMARK_ADVANCED(name) \ | ||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name) | ||
|
||
#endif | ||
|
||
#endif // CATCH_BENCHMARK_HPP_INCLUDED |
46 changes: 46 additions & 0 deletions
46
thirdparty/catch2/src/main/native/include/catch2/benchmark/catch_benchmark_all.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
// Copyright Catch2 Authors | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.txt or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
// SPDX-License-Identifier: BSL-1.0 | ||
/** \file | ||
* This is a convenience header for Catch2's benchmarking. It includes | ||
* **all** of Catch2 headers related to benchmarking. | ||
* | ||
* Generally the Catch2 users should use specific includes they need, | ||
* but this header can be used instead for ease-of-experimentation, or | ||
* just plain convenience, at the cost of (significantly) increased | ||
* compilation times. | ||
* | ||
* When a new header is added to either the `benchmark` folder, or to | ||
* the corresponding internal (detail) subfolder, it should be added here. | ||
*/ | ||
|
||
#ifndef CATCH_BENCHMARK_ALL_HPP_INCLUDED | ||
#define CATCH_BENCHMARK_ALL_HPP_INCLUDED | ||
|
||
#include <catch2/benchmark/catch_benchmark.hpp> | ||
#include <catch2/benchmark/catch_chronometer.hpp> | ||
#include <catch2/benchmark/catch_clock.hpp> | ||
#include <catch2/benchmark/catch_constructor.hpp> | ||
#include <catch2/benchmark/catch_environment.hpp> | ||
#include <catch2/benchmark/catch_estimate.hpp> | ||
#include <catch2/benchmark/catch_execution_plan.hpp> | ||
#include <catch2/benchmark/catch_optimizer.hpp> | ||
#include <catch2/benchmark/catch_outlier_classification.hpp> | ||
#include <catch2/benchmark/catch_sample_analysis.hpp> | ||
#include <catch2/benchmark/detail/catch_analyse.hpp> | ||
#include <catch2/benchmark/detail/catch_benchmark_function.hpp> | ||
#include <catch2/benchmark/detail/catch_benchmark_stats.hpp> | ||
#include <catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp> | ||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp> | ||
#include <catch2/benchmark/detail/catch_estimate_clock.hpp> | ||
#include <catch2/benchmark/detail/catch_measure.hpp> | ||
#include <catch2/benchmark/detail/catch_repeat.hpp> | ||
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp> | ||
#include <catch2/benchmark/detail/catch_stats.hpp> | ||
#include <catch2/benchmark/detail/catch_timing.hpp> | ||
|
||
#endif // CATCH_BENCHMARK_ALL_HPP_INCLUDED |
77 changes: 77 additions & 0 deletions
77
thirdparty/catch2/src/main/native/include/catch2/benchmark/catch_chronometer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
// Copyright Catch2 Authors | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.txt or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
// SPDX-License-Identifier: BSL-1.0 | ||
// Adapted from donated nonius code. | ||
|
||
#ifndef CATCH_CHRONOMETER_HPP_INCLUDED | ||
#define CATCH_CHRONOMETER_HPP_INCLUDED | ||
|
||
#include <catch2/benchmark/catch_clock.hpp> | ||
#include <catch2/benchmark/catch_optimizer.hpp> | ||
#include <catch2/internal/catch_meta.hpp> | ||
#include <catch2/internal/catch_move_and_forward.hpp> | ||
|
||
namespace Catch { | ||
namespace Benchmark { | ||
namespace Detail { | ||
struct ChronometerConcept { | ||
virtual void start() = 0; | ||
virtual void finish() = 0; | ||
virtual ~ChronometerConcept(); // = default; | ||
|
||
ChronometerConcept() = default; | ||
ChronometerConcept(ChronometerConcept const&) = default; | ||
ChronometerConcept& operator=(ChronometerConcept const&) = default; | ||
}; | ||
template <typename Clock> | ||
struct ChronometerModel final : public ChronometerConcept { | ||
void start() override { started = Clock::now(); } | ||
void finish() override { finished = Clock::now(); } | ||
|
||
IDuration elapsed() const { | ||
return std::chrono::duration_cast<std::chrono::nanoseconds>( | ||
finished - started ); | ||
} | ||
|
||
TimePoint<Clock> started; | ||
TimePoint<Clock> finished; | ||
}; | ||
} // namespace Detail | ||
|
||
struct Chronometer { | ||
public: | ||
template <typename Fun> | ||
void measure(Fun&& fun) { measure(CATCH_FORWARD(fun), is_callable<Fun(int)>()); } | ||
|
||
int runs() const { return repeats; } | ||
|
||
Chronometer(Detail::ChronometerConcept& meter, int repeats_) | ||
: impl(&meter) | ||
, repeats(repeats_) {} | ||
|
||
private: | ||
template <typename Fun> | ||
void measure(Fun&& fun, std::false_type) { | ||
measure([&fun](int) { return fun(); }, std::true_type()); | ||
} | ||
|
||
template <typename Fun> | ||
void measure(Fun&& fun, std::true_type) { | ||
Detail::optimizer_barrier(); | ||
impl->start(); | ||
for (int i = 0; i < repeats; ++i) invoke_deoptimized(fun, i); | ||
impl->finish(); | ||
Detail::optimizer_barrier(); | ||
} | ||
|
||
Detail::ChronometerConcept* impl; | ||
int repeats; | ||
}; | ||
} // namespace Benchmark | ||
} // namespace Catch | ||
|
||
#endif // CATCH_CHRONOMETER_HPP_INCLUDED |
27 changes: 27 additions & 0 deletions
27
thirdparty/catch2/src/main/native/include/catch2/benchmark/catch_clock.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
// Copyright Catch2 Authors | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.txt or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
// SPDX-License-Identifier: BSL-1.0 | ||
// Adapted from donated nonius code. | ||
|
||
#ifndef CATCH_CLOCK_HPP_INCLUDED | ||
#define CATCH_CLOCK_HPP_INCLUDED | ||
|
||
#include <chrono> | ||
|
||
namespace Catch { | ||
namespace Benchmark { | ||
using IDuration = std::chrono::nanoseconds; | ||
using FDuration = std::chrono::duration<double, std::nano>; | ||
|
||
template <typename Clock> | ||
using TimePoint = typename Clock::time_point; | ||
|
||
using default_clock = std::chrono::steady_clock; | ||
} // namespace Benchmark | ||
} // namespace Catch | ||
|
||
#endif // CATCH_CLOCK_HPP_INCLUDED |
Oops, something went wrong.