From a3a9eb89ee992c5d29cbb90e7d10f7c8eb3bd4a3 Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 25 Jun 2025 17:56:36 +0200 Subject: [PATCH 1/3] chore(examples): make build fail on any warning --- examples/google_benchmark_bazel/BUILD.bazel | 1 + examples/google_benchmark_cmake/CMakeLists.txt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/examples/google_benchmark_bazel/BUILD.bazel b/examples/google_benchmark_bazel/BUILD.bazel index d30cce5..444a4dc 100644 --- a/examples/google_benchmark_bazel/BUILD.bazel +++ b/examples/google_benchmark_bazel/BUILD.bazel @@ -1,6 +1,7 @@ cc_binary( name = "my_benchmark", srcs = glob(["*.cpp", "*.hpp"]), + copts = ["-Wall", "-Wextra", "-Werror"], deps = [ "//google_benchmark:benchmark", ], diff --git a/examples/google_benchmark_cmake/CMakeLists.txt b/examples/google_benchmark_cmake/CMakeLists.txt index f8f8fc4..3d3067a 100644 --- a/examples/google_benchmark_cmake/CMakeLists.txt +++ b/examples/google_benchmark_cmake/CMakeLists.txt @@ -3,6 +3,11 @@ include(FetchContent) project(codspeed_picobench_compat VERSION 0.0.0 LANGUAGES CXX) +# Treat warnings as errors +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + add_compile_options(-Wall -Wextra -Werror) +endif() + # On the small benchmarks of this repo, most of the benches will be optimized out, but this is expected. set(CMAKE_BUILD_TYPE RelWithDebInfo) From d5b4b775982fd8b6a5f9db4a9336ea8ad4c1ef42 Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 25 Jun 2025 17:47:57 +0200 Subject: [PATCH 2/3] fix(core): remove unused variables --- core/src/walltime.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/core/src/walltime.cpp b/core/src/walltime.cpp index 0dfa80c..23b8c4b 100644 --- a/core/src/walltime.cpp +++ b/core/src/walltime.cpp @@ -18,9 +18,6 @@ namespace codspeed { -const double IQR_OUTLIER_FACTOR = 1.5; -const double STDEV_OUTLIER_FACTOR = 3.0; - // Times are per iteration struct BenchmarkStats { double min_ns; @@ -63,8 +60,7 @@ double compute_quantile(const std::vector &data, double quantile) { } void compute_iqr_and_outliers(const std::vector ×_ns, double mean, - double median, double stdev, double &q1, - double &q3, double &iqr, + double stdev, double &q1, double &q3, double &iqr, size_t &iqr_outlier_rounds, size_t &stdev_outlier_rounds) { std::vector sorted_times = times_ns; @@ -217,9 +213,8 @@ void generate_codspeed_walltime_report( double stdev = raw_benchmark.stdev_ns; double q1, q3, iqr; size_t iqr_outlier_rounds, stdev_outlier_rounds; - compute_iqr_and_outliers(raw_benchmark.round_times_ns, mean, median, stdev, - q1, q3, iqr, iqr_outlier_rounds, - stdev_outlier_rounds); + compute_iqr_and_outliers(raw_benchmark.round_times_ns, mean, stdev, q1, q3, + iqr, iqr_outlier_rounds, stdev_outlier_rounds); // Populate stats codspeed_benchmark.stats = { From d68b80218493217a919bac2a3dbac7b2529360dc Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 25 Jun 2025 17:48:56 +0200 Subject: [PATCH 3/3] fix(examples): remove compilation warning about unused variables --- .../google_benchmark_cmake/fixture_bench.hpp | 21 +++++++++++-------- examples/google_benchmark_cmake/main.cpp | 10 +++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/google_benchmark_cmake/fixture_bench.hpp b/examples/google_benchmark_cmake/fixture_bench.hpp index 738ba31..ff2d4e3 100644 --- a/examples/google_benchmark_cmake/fixture_bench.hpp +++ b/examples/google_benchmark_cmake/fixture_bench.hpp @@ -4,16 +4,15 @@ #ifndef FIXTURE_BENCH_HPP #define FIXTURE_BENCH_HPP - #include namespace example_namespace { class MyFixture : public benchmark::Fixture { -public: - void SetUp(::benchmark::State &state) {} + public: + void SetUp(::benchmark::State &state) { (void)state; } - void TearDown(::benchmark::State &state) {} + void TearDown(::benchmark::State &state) { (void)state; } }; BENCHMARK_F(MyFixture, FooTest)(benchmark::State &st) { for (auto _ : st) { @@ -28,7 +27,8 @@ BENCHMARK_REGISTER_F(MyFixture, BarTest); // // -template class MyTemplatedFixture : public benchmark::Fixture {}; +template +class MyTemplatedFixture : public benchmark::Fixture {}; BENCHMARK_TEMPLATE_F(MyTemplatedFixture, IntTest, int)(benchmark::State &st) { for (auto _ : st) { } @@ -43,7 +43,8 @@ BENCHMARK_REGISTER_F(MyTemplatedFixture, DoubleTest); // // -template class MyTemplate1 : public benchmark::Fixture {}; +template +class MyTemplate1 : public benchmark::Fixture {}; BENCHMARK_TEMPLATE1_DEFINE_F(MyTemplate1, TestA, int)(benchmark::State &st) { for (auto _ : st) { } @@ -53,13 +54,15 @@ BENCHMARK_REGISTER_F(MyTemplate1, TestA); // // -template class MyTemplate2 : public benchmark::Fixture {}; -BENCHMARK_TEMPLATE2_DEFINE_F(MyTemplate2, TestB, int, double)(benchmark::State &st) { +template +class MyTemplate2 : public benchmark::Fixture {}; +BENCHMARK_TEMPLATE2_DEFINE_F(MyTemplate2, TestB, int, + double)(benchmark::State &st) { for (auto _ : st) { } } BENCHMARK_REGISTER_F(MyTemplate2, TestB); -} +} // namespace example_namespace #endif diff --git a/examples/google_benchmark_cmake/main.cpp b/examples/google_benchmark_cmake/main.cpp index 496ae3f..035ae45 100644 --- a/examples/google_benchmark_cmake/main.cpp +++ b/examples/google_benchmark_cmake/main.cpp @@ -1,11 +1,14 @@ -#include "fixture_bench.hpp" -#include "template_bench.hpp" #include + #include +#include "fixture_bench.hpp" +#include "template_bench.hpp" + template void BM_Capture(benchmark::State &state, Args &&...args) { auto args_tuple = std::make_tuple(std::move(args)...); + (void)args_tuple; for (auto _ : state) { } } @@ -36,8 +39,7 @@ static void BM_memcpy(benchmark::State &state) { char *src = new char[state.range(0)]; char *dst = new char[state.range(0)]; memset(src, 'x', state.range(0)); - for (auto _ : state) - memcpy(dst, src, state.range(0)); + for (auto _ : state) memcpy(dst, src, state.range(0)); delete[] src; delete[] dst; }