Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/benchmark
diff options
context:
space:
mode:
authorMartin Hořeňovský2024-07-22 09:50:24 +0200
committerMartin Hořeňovský2024-07-22 10:54:14 +0200
commit22e6490325318d9a0c9820f7e1bb43c993adbbec (patch)
tree1631c6f8159e982b49729c4a05bc996d2caa751d /src/catch2/benchmark
parent595bf9864e4274bd8a4261b733a5d4576e070f19 (diff)
downloadcatch3-22e6490325318d9a0c9820f7e1bb43c993adbbec.tar.gz
Remove copyability from BenchmarkFunction
Technically we should be able to remove moveability as well, but then we would need a larger surgery. This already improves the compile times and binary sizes by a surprising amount.
Diffstat (limited to 'src/catch2/benchmark')
-rw-r--r--src/catch2/benchmark/catch_benchmark.hpp4
-rw-r--r--src/catch2/benchmark/detail/catch_benchmark_function.cpp6
-rw-r--r--src/catch2/benchmark/detail/catch_benchmark_function.hpp25
-rw-r--r--src/catch2/benchmark/detail/catch_measure.hpp2
4 files changed, 12 insertions, 25 deletions
diff --git a/src/catch2/benchmark/catch_benchmark.hpp b/src/catch2/benchmark/catch_benchmark.hpp
index 3db40bb0..d0f88cfc 100644
--- a/src/catch2/benchmark/catch_benchmark.hpp
+++ b/src/catch2/benchmark/catch_benchmark.hpp
@@ -45,12 +45,12 @@ namespace Catch {
: fun(CATCH_MOVE(func)), name(CATCH_MOVE(benchmarkName)) {}
template <typename Clock>
- ExecutionPlan prepare(const IConfig &cfg, Environment env) const {
+ 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(), fun, std::chrono::duration_cast<FDuration>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations };
+ 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>
diff --git a/src/catch2/benchmark/detail/catch_benchmark_function.cpp b/src/catch2/benchmark/detail/catch_benchmark_function.cpp
index b437d049..66d4e619 100644
--- a/src/catch2/benchmark/detail/catch_benchmark_function.cpp
+++ b/src/catch2/benchmark/detail/catch_benchmark_function.cpp
@@ -11,7 +11,13 @@
namespace Catch {
namespace Benchmark {
namespace Detail {
+ struct do_nothing {
+ void operator()() const {}
+ };
+
BenchmarkFunction::callable::~callable() = default;
+ BenchmarkFunction::BenchmarkFunction():
+ f( new model<do_nothing>{ {} } ){}
} // namespace Detail
} // namespace Benchmark
} // namespace Catch
diff --git a/src/catch2/benchmark/detail/catch_benchmark_function.hpp b/src/catch2/benchmark/detail/catch_benchmark_function.hpp
index 144e4b6e..a03cb112 100644
--- a/src/catch2/benchmark/detail/catch_benchmark_function.hpp
+++ b/src/catch2/benchmark/detail/catch_benchmark_function.hpp
@@ -35,22 +35,17 @@ namespace Catch {
private:
struct callable {
virtual void call(Chronometer meter) const = 0;
- virtual Catch::Detail::unique_ptr<callable> clone() const = 0;
virtual ~callable(); // = default;
callable() = default;
- callable(callable const&) = default;
- callable& operator=(callable const&) = default;
+ callable(callable&&) = default;
+ callable& operator=(callable&&) = default;
};
template <typename Fun>
struct model : public callable {
model(Fun&& fun_) : fun(CATCH_MOVE(fun_)) {}
model(Fun const& fun_) : fun(fun_) {}
- Catch::Detail::unique_ptr<callable> clone() const override {
- return Catch::Detail::make_unique<model<Fun>>( *this );
- }
-
void call(Chronometer meter) const override {
call(meter, is_callable<Fun(Chronometer)>());
}
@@ -64,14 +59,8 @@ namespace Catch {
Fun fun;
};
- struct do_nothing { void operator()() const {} };
-
- template <typename T>
- BenchmarkFunction(model<T>* c) : f(c) {}
-
public:
- BenchmarkFunction()
- : f(new model<do_nothing>{ {} }) {}
+ BenchmarkFunction();
template <typename Fun,
std::enable_if_t<!is_related<Fun, BenchmarkFunction>::value, int> = 0>
@@ -81,20 +70,12 @@ namespace Catch {
BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
f( CATCH_MOVE( that.f ) ) {}
- BenchmarkFunction(BenchmarkFunction const& that)
- : f(that.f->clone()) {}
-
BenchmarkFunction&
operator=( BenchmarkFunction&& that ) noexcept {
f = CATCH_MOVE( that.f );
return *this;
}
- BenchmarkFunction& operator=(BenchmarkFunction const& that) {
- f = that.f->clone();
- return *this;
- }
-
void operator()(Chronometer meter) const { f->call(meter); }
private:
diff --git a/src/catch2/benchmark/detail/catch_measure.hpp b/src/catch2/benchmark/detail/catch_measure.hpp
index 37494a68..a8049072 100644
--- a/src/catch2/benchmark/detail/catch_measure.hpp
+++ b/src/catch2/benchmark/detail/catch_measure.hpp
@@ -20,7 +20,7 @@ namespace Catch {
template <typename Clock, typename Fun, typename... Args>
TimingOf<Fun, Args...> measure(Fun&& fun, Args&&... args) {
auto start = Clock::now();
- auto&& r = Detail::complete_invoke(fun, CATCH_FORWARD(args)...);
+ auto&& r = Detail::complete_invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...);
auto end = Clock::now();
auto delta = end - start;
return { delta, CATCH_FORWARD(r), 1 };