Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions test/include/seqan3/test/compatibility/benchmark.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause

/*!\file
* \brief Provides API compatibility for newer google/benchmark versions.
* \author Enrico Seiler <enrico.seiler AT fu-berlin.de>
*/

#pragma once

#include <benchmark/benchmark.h>

#include <seqan3/core/platform.hpp>

/*!\brief Provide benchmark::Benchmark for old google/benchmark versions.
* \sa https://github.com/google/benchmark/pull/2101
* \details
*
* Google benchmark moved its `Benchmark` class from `benchmark::internal` to `benchmark`.
* In old versions, `benchmark::Benchmark` does not exist.
* In new versions, `benchmark::internal::Benchmark` will trigger a deprecation warning.
*
* Here is a reduced example of the change:
* ```cpp
* #ifdef OLD
* namespace benchmark
* {
* namespace internal
* {
* class Benchmark{};
* }
* }
* #endif
*
* #ifdef NEW
* namespace benchmark
* {
* class Benchmark{};
*
* namespace internal
* {
* using Benchmark [[deprecated("Use benchmark::Benchmark instead")]] = ::benchmark::Benchmark;
* }
* }
* #endif
* ```
*
* Because we do not necessarily require a specific version of benchmark, and, at the time of writing, the new change
* is not yet included in a release, we want to already use the new API but also not break the old API.
*
* ### Version 1
* https://godbolt.org/z/zzWdojW4G
*
* We can simply alias `benchmark::internal::Benchmark` to `benchmark::Benchmark` but ignore the deprecation warning.
* The advantage of this version is that it is easy to understand (both code and intention), but it will break once
* `benchmark::internal::Benchmark` is removed.
*
* ```cpp
* namespace benchmark
* {
*
* #pragma GCC diagnostic push
* #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
* using Benchmark = ::benchmark::internal::Benchmark;
* #pragma GCC diagnostic pop
*
* }
* ```
*
* ### Version 2
* https://godbolt.org/z/1M9f8fojv
*
* We use an anonymous namespace within `benchmark` to resolve `Benchmark` from either location without triggering
* deprecation warnings. The anonymous namespace brings both `benchmark` and `benchmark::internal` into scope, then
* aliases the first available `Benchmark` type. This works for both old and new versions and is future-proof, albeit
* harder to grasp (both code and intention).
*
* ```cpp
* namespace benchmark
* {
*
* namespace
* {
*
* using namespace benchmark;
* using namespace benchmark::internal;
* using Benchmark = Benchmark;
*
* }
*
* }
* ```
*/
namespace benchmark
{

namespace
{

using namespace benchmark;
using namespace benchmark::internal;
using Benchmark = Benchmark;

} // namespace

} // namespace benchmark
9 changes: 1 addition & 8 deletions test/performance/range/gap_decorator_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
#include <seqan3/alignment/decorator/gap_decorator.hpp>
#include <seqan3/alignment/exception.hpp>
#include <seqan3/alphabet/all.hpp>

namespace benchmark
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
using Benchmark = benchmark::internal::Benchmark;
#pragma GCC diagnostic pop
} // namespace benchmark
#include <seqan3/test/compatibility/benchmark.hpp>

#define SEQAN3_LEN_LONG 1 << 18
#define SEQAN3_LEN_SHORT 1 << 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
#include <benchmark/benchmark.h>

#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
#include <seqan3/test/compatibility/benchmark.hpp>
#include <seqan3/test/performance/sequence_generator.hpp>
#include <seqan3/utility/range/to.hpp>
#include <seqan3/utility/views/zip.hpp>

namespace benchmark
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
using Benchmark = benchmark::internal::Benchmark;
#pragma GCC diagnostic pop
} // namespace benchmark

inline benchmark::Counter hashes_per_second(size_t const count)
{
return benchmark::Counter(count, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000);
Expand Down
9 changes: 1 addition & 8 deletions test/performance/search/index_construction_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/views/rank_to.hpp>
#include <seqan3/search/fm_index/all.hpp>
#include <seqan3/test/compatibility/benchmark.hpp>
#include <seqan3/test/performance/sequence_generator.hpp>
#include <seqan3/test/seqan2.hpp>
#include <seqan3/utility/range/to.hpp>
Expand All @@ -17,14 +18,6 @@
# include <seqan/index.h>
#endif

namespace benchmark
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
using Benchmark = benchmark::internal::Benchmark;
#pragma GCC diagnostic pop
} // namespace benchmark

static constexpr int32_t max_length{50000};
static constexpr size_t seed{0x6'12'6f};

Expand Down
9 changes: 1 addition & 8 deletions test/performance/search/views/view_kmer_hash_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
#include <seqan3/test/compatibility/benchmark.hpp>
#include <seqan3/test/performance/sequence_generator.hpp>
#include <seqan3/test/performance/units.hpp>

#ifdef SEQAN3_HAS_SEQAN2
# include <seqan/index.h>
#endif // SEQAN3_HAS_SEQAN2

namespace benchmark
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
using Benchmark = benchmark::internal::Benchmark;
#pragma GCC diagnostic pop
} // namespace benchmark

inline benchmark::Counter bp_per_second(size_t const basepairs)
{
return benchmark::Counter(basepairs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/search/views/minimiser_hash.hpp>
#include <seqan3/test/compatibility/benchmark.hpp>
#include <seqan3/test/performance/sequence_generator.hpp>
#include <seqan3/test/performance/units.hpp>
#include <seqan3/utility/views/zip.hpp>
Expand All @@ -16,14 +17,6 @@
# include <seqan/index.h>
#endif // SEQAN3_HAS_SEQAN2

namespace benchmark
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
using Benchmark = benchmark::internal::Benchmark;
#pragma GCC diagnostic pop
} // namespace benchmark

inline benchmark::Counter bp_per_second(size_t const basepairs)
{
return benchmark::Counter(basepairs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@

#include <benchmark/benchmark.h>

#include <seqan3/test/compatibility/benchmark.hpp>
#include <seqan3/test/performance/sequence_generator.hpp>
#include <seqan3/utility/bloom_filter/bloom_filter.hpp>

namespace benchmark
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
using Benchmark = benchmark::internal::Benchmark;
#pragma GCC diagnostic pop
} // namespace benchmark

inline benchmark::Counter hashes_per_second(size_t const count)
{
return benchmark::Counter(count, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000);
Expand Down