From 286cdc4fc31632e062bac1448b31a30f030d3191 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Mon, 13 Nov 2023 14:32:47 +0100 Subject: [PATCH 1/2] [FIX] libc++: performance tests --- test/include/seqan3/test/performance/units.hpp | 4 +++- test/performance/io/format_vienna_benchmark.cpp | 10 +++++----- .../io/lowlevel_stream_input_benchmark.cpp | 13 ++++++++++++- .../range/container_assignment_benchmark.cpp | 6 +++--- .../range/container_push_back_benchmark.cpp | 4 ++-- .../range/container_seq_read_benchmark.cpp | 13 ++++++++----- .../range/container_seq_write_benchmark.cpp | 6 +++--- .../search/views/view_minimiser_hash_benchmark.cpp | 6 +++--- .../utility/simd/views/iota_simd_benchmark.cpp | 2 +- test/seqan3-test.cmake | 2 ++ 10 files changed, 42 insertions(+), 24 deletions(-) diff --git a/test/include/seqan3/test/performance/units.hpp b/test/include/seqan3/test/performance/units.hpp index ed40f0dc46..200c046410 100644 --- a/test/include/seqan3/test/performance/units.hpp +++ b/test/include/seqan3/test/performance/units.hpp @@ -38,12 +38,14 @@ inline benchmark::Counter bytes_per_second(size_t bytes) template inline size_t pairwise_cell_updates(sequences_range_t const & sequences_range, [[maybe_unused]] auto && align_cfg) { + using config_t = std::remove_cvref_t; + auto count_cells = [&](auto && seq1, auto && seq2) { size_t const columns = std::ranges::size(seq1) + 1; size_t const rows = std::ranges::size(seq2) + 1; - if constexpr (align_cfg.template exists()) + if constexpr (config_t::template exists()) { using std::get; auto const band_cfg = get(align_cfg); diff --git a/test/performance/io/format_vienna_benchmark.cpp b/test/performance/io/format_vienna_benchmark.cpp index 38e1189102..3c83c48579 100644 --- a/test/performance/io/format_vienna_benchmark.cpp +++ b/test/performance/io/format_vienna_benchmark.cpp @@ -26,18 +26,18 @@ inline constexpr size_t iterations_per_run = 1024; -inline std::string const header{"seq foobar blobber"}; -inline auto const rna_sequence = seqan3::test::generate_sequence(474, 0, 0); -auto const sequence = rna_sequence | seqan3::views::to_char | seqan3::ranges::to(); +static std::string const header{"seq foobar blobber"}; +static inline auto const rna_sequence = seqan3::test::generate_sequence(474, 0, 0); +static auto const sequence = rna_sequence | seqan3::views::to_char | seqan3::ranges::to(); -inline std::string const structure{"(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))......." +static std::string const structure{"(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))......." "(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))......." "(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))......." "(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))......." "(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))......." "(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))......."}; -inline std::string const vienna_file = []() +static std::string const vienna_file = []() { std::string file{}; for (size_t idx = 0; idx < iterations_per_run; idx++) diff --git a/test/performance/io/lowlevel_stream_input_benchmark.cpp b/test/performance/io/lowlevel_stream_input_benchmark.cpp index 5035c41b76..8f00da87dc 100644 --- a/test/performance/io/lowlevel_stream_input_benchmark.cpp +++ b/test/performance/io/lowlevel_stream_input_benchmark.cpp @@ -47,41 +47,49 @@ void read_all(benchmark::State & state) } /* start benchmark */ - char c{}; // prevents optimisation if constexpr (id == tag::std_stream_it) { for (auto _ : state) { + char c{}; std::ifstream s{filename, std::ios::binary}; std::istream_iterator it{s}; std::istream_iterator e{}; for (; it != e; ++it) c += *it; + + benchmark::DoNotOptimize(c); } } else if constexpr (id == tag::std_streambuf_it) { for (auto _ : state) { + char c{}; std::ifstream s{filename, std::ios::binary}; std::istreambuf_iterator it{s}; std::istreambuf_iterator e{}; for (; it != e; ++it) c += *it; + + benchmark::DoNotOptimize(c); } } else if constexpr (id == tag::seqan3_streambuf_it) { for (auto _ : state) { + char c{}; std::ifstream s{filename, std::ios::binary}; seqan3::detail::fast_istreambuf_iterator it{*s.rdbuf()}; std::default_sentinel_t e{}; for (; it != e; ++it) c += *it; + + benchmark::DoNotOptimize(c); } } #ifdef SEQAN3_HAS_SEQAN2 @@ -89,11 +97,14 @@ void read_all(benchmark::State & state) { for (auto _ : state) { + char c{}; std::ifstream s{filename, std::ios::binary}; auto it = seqan2::Iter>{s}; for (; !seqan2::atEnd(it); ++it) c += *it; + + benchmark::DoNotOptimize(c); } } #endif diff --git a/test/performance/range/container_assignment_benchmark.cpp b/test/performance/range/container_assignment_benchmark.cpp index 7208781a31..e22ad21e64 100644 --- a/test/performance/range/container_assignment_benchmark.cpp +++ b/test/performance/range/container_assignment_benchmark.cpp @@ -86,7 +86,7 @@ static constexpr void resize(container_t & container, } #endif // SEQAN3_HAS_SEQAN2 -template typename container_t, typename alphabet_t> +template typename container_t, typename alphabet_t, typename... args> static void assign(benchmark::State & state) { auto random_sequence = []() constexpr @@ -99,10 +99,10 @@ static void assign(benchmark::State & state) #endif // SEQAN3_HAS_SEQAN2 }(); - container_t from{}; + container_t from{}; resize(from, vector_size); std::copy(std::ranges::begin(random_sequence), std::ranges::end(random_sequence), std::ranges::begin(from)); - container_t to{}; + container_t to{}; resize(to, vector_size); assignment_functor fn{}; diff --git a/test/performance/range/container_push_back_benchmark.cpp b/test/performance/range/container_push_back_benchmark.cpp index 32470ac9b8..b49bbdeada 100644 --- a/test/performance/range/container_push_back_benchmark.cpp +++ b/test/performance/range/container_push_back_benchmark.cpp @@ -29,14 +29,14 @@ using small_vec = seqan3::small_vector; // push_back // ============================================================================ -template