Skip to content

Commit a13d694

Browse files
authored
Merge pull request #3395 from eseiler/fix/bench
refactor: benchmark workaround
2 parents de29ca6 + 63cf0db commit a13d694

File tree

7 files changed

+113
-48
lines changed

7 files changed

+113
-48
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2+
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
/*!\file
6+
* \brief Provides API compatibility for newer google/benchmark versions.
7+
* \author Enrico Seiler <enrico.seiler AT fu-berlin.de>
8+
*/
9+
10+
#pragma once
11+
12+
#include <benchmark/benchmark.h>
13+
14+
#include <seqan3/core/platform.hpp>
15+
16+
/*!\brief Provide benchmark::Benchmark for old google/benchmark versions.
17+
* \sa https://github.com/google/benchmark/pull/2101
18+
* \details
19+
*
20+
* Google benchmark moved its `Benchmark` class from `benchmark::internal` to `benchmark`.
21+
* In old versions, `benchmark::Benchmark` does not exist.
22+
* In new versions, `benchmark::internal::Benchmark` will trigger a deprecation warning.
23+
*
24+
* Here is a reduced example of the change:
25+
* ```cpp
26+
* #ifdef OLD
27+
* namespace benchmark
28+
* {
29+
* namespace internal
30+
* {
31+
* class Benchmark{};
32+
* }
33+
* }
34+
* #endif
35+
*
36+
* #ifdef NEW
37+
* namespace benchmark
38+
* {
39+
* class Benchmark{};
40+
*
41+
* namespace internal
42+
* {
43+
* using Benchmark [[deprecated("Use benchmark::Benchmark instead")]] = ::benchmark::Benchmark;
44+
* }
45+
* }
46+
* #endif
47+
* ```
48+
*
49+
* Because we do not necessarily require a specific version of benchmark, and, at the time of writing, the new change
50+
* is not yet included in a release, we want to already use the new API but also not break the old API.
51+
*
52+
* ### Version 1
53+
* https://godbolt.org/z/zzWdojW4G
54+
*
55+
* We can simply alias `benchmark::internal::Benchmark` to `benchmark::Benchmark` but ignore the deprecation warning.
56+
* The advantage of this version is that it is easy to understand (both code and intention), but it will break once
57+
* `benchmark::internal::Benchmark` is removed.
58+
*
59+
* ```cpp
60+
* namespace benchmark
61+
* {
62+
*
63+
* #pragma GCC diagnostic push
64+
* #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
65+
* using Benchmark = ::benchmark::internal::Benchmark;
66+
* #pragma GCC diagnostic pop
67+
*
68+
* }
69+
* ```
70+
*
71+
* ### Version 2
72+
* https://godbolt.org/z/1M9f8fojv
73+
*
74+
* We use an anonymous namespace within `benchmark` to resolve `Benchmark` from either location without triggering
75+
* deprecation warnings. The anonymous namespace brings both `benchmark` and `benchmark::internal` into scope, then
76+
* aliases the first available `Benchmark` type. This works for both old and new versions and is future-proof, albeit
77+
* harder to grasp (both code and intention).
78+
*
79+
* ```cpp
80+
* namespace benchmark
81+
* {
82+
*
83+
* namespace
84+
* {
85+
*
86+
* using namespace benchmark;
87+
* using namespace benchmark::internal;
88+
* using Benchmark = Benchmark;
89+
*
90+
* }
91+
*
92+
* }
93+
* ```
94+
*/
95+
namespace benchmark
96+
{
97+
98+
namespace
99+
{
100+
101+
using namespace benchmark;
102+
using namespace benchmark::internal;
103+
using Benchmark = Benchmark;
104+
105+
} // namespace
106+
107+
} // namespace benchmark

test/performance/range/gap_decorator_helper.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@
1515
#include <seqan3/alignment/decorator/gap_decorator.hpp>
1616
#include <seqan3/alignment/exception.hpp>
1717
#include <seqan3/alphabet/all.hpp>
18-
19-
namespace benchmark
20-
{
21-
#pragma GCC diagnostic push
22-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
23-
using Benchmark = benchmark::internal::Benchmark;
24-
#pragma GCC diagnostic pop
25-
} // namespace benchmark
18+
#include <seqan3/test/compatibility/benchmark.hpp>
2619

2720
#define SEQAN3_LEN_LONG 1 << 18
2821
#define SEQAN3_LEN_SHORT 1 << 12

test/performance/search/dream_index/interleaved_bloom_filter_benchmark.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@
55
#include <benchmark/benchmark.h>
66

77
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
8+
#include <seqan3/test/compatibility/benchmark.hpp>
89
#include <seqan3/test/performance/sequence_generator.hpp>
910
#include <seqan3/utility/range/to.hpp>
1011
#include <seqan3/utility/views/zip.hpp>
1112

12-
namespace benchmark
13-
{
14-
#pragma GCC diagnostic push
15-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
16-
using Benchmark = benchmark::internal::Benchmark;
17-
#pragma GCC diagnostic pop
18-
} // namespace benchmark
19-
2013
inline benchmark::Counter hashes_per_second(size_t const count)
2114
{
2215
return benchmark::Counter(count, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000);

test/performance/search/index_construction_benchmark.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <seqan3/alphabet/nucleotide/dna4.hpp>
99
#include <seqan3/alphabet/views/rank_to.hpp>
1010
#include <seqan3/search/fm_index/all.hpp>
11+
#include <seqan3/test/compatibility/benchmark.hpp>
1112
#include <seqan3/test/performance/sequence_generator.hpp>
1213
#include <seqan3/test/seqan2.hpp>
1314
#include <seqan3/utility/range/to.hpp>
@@ -17,14 +18,6 @@
1718
# include <seqan/index.h>
1819
#endif
1920

20-
namespace benchmark
21-
{
22-
#pragma GCC diagnostic push
23-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
24-
using Benchmark = benchmark::internal::Benchmark;
25-
#pragma GCC diagnostic pop
26-
} // namespace benchmark
27-
2821
static constexpr int32_t max_length{50000};
2922
static constexpr size_t seed{0x6'12'6f};
3023

test/performance/search/views/view_kmer_hash_benchmark.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@
66

77
#include <seqan3/alphabet/nucleotide/dna4.hpp>
88
#include <seqan3/search/views/kmer_hash.hpp>
9+
#include <seqan3/test/compatibility/benchmark.hpp>
910
#include <seqan3/test/performance/sequence_generator.hpp>
1011
#include <seqan3/test/performance/units.hpp>
1112

1213
#ifdef SEQAN3_HAS_SEQAN2
1314
# include <seqan/index.h>
1415
#endif // SEQAN3_HAS_SEQAN2
1516

16-
namespace benchmark
17-
{
18-
#pragma GCC diagnostic push
19-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20-
using Benchmark = benchmark::internal::Benchmark;
21-
#pragma GCC diagnostic pop
22-
} // namespace benchmark
23-
2417
inline benchmark::Counter bp_per_second(size_t const basepairs)
2518
{
2619
return benchmark::Counter(basepairs,

test/performance/search/views/view_minimiser_hash_benchmark.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <seqan3/alphabet/nucleotide/dna4.hpp>
88
#include <seqan3/search/views/minimiser_hash.hpp>
9+
#include <seqan3/test/compatibility/benchmark.hpp>
910
#include <seqan3/test/performance/sequence_generator.hpp>
1011
#include <seqan3/test/performance/units.hpp>
1112
#include <seqan3/utility/views/zip.hpp>
@@ -16,14 +17,6 @@
1617
# include <seqan/index.h>
1718
#endif // SEQAN3_HAS_SEQAN2
1819

19-
namespace benchmark
20-
{
21-
#pragma GCC diagnostic push
22-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
23-
using Benchmark = benchmark::internal::Benchmark;
24-
#pragma GCC diagnostic pop
25-
} // namespace benchmark
26-
2720
inline benchmark::Counter bp_per_second(size_t const basepairs)
2821
{
2922
return benchmark::Counter(basepairs,

test/performance/utility/bloom_filter/bloom_filter_benchmark.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@
44

55
#include <benchmark/benchmark.h>
66

7+
#include <seqan3/test/compatibility/benchmark.hpp>
78
#include <seqan3/test/performance/sequence_generator.hpp>
89
#include <seqan3/utility/bloom_filter/bloom_filter.hpp>
910

10-
namespace benchmark
11-
{
12-
#pragma GCC diagnostic push
13-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
14-
using Benchmark = benchmark::internal::Benchmark;
15-
#pragma GCC diagnostic pop
16-
} // namespace benchmark
17-
1811
inline benchmark::Counter hashes_per_second(size_t const count)
1912
{
2013
return benchmark::Counter(count, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000);

0 commit comments

Comments
 (0)