Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] libc++: performance tests #3211

Merged
merged 2 commits into from
Nov 16, 2023
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
7 changes: 7 additions & 0 deletions .github/workflows/ci_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ jobs:
build_type: Release
test_threads: 1 # snippets create and delete files and some separate tests create/delete the same files

- name: "Performance clang17 libc++"
compiler: "clang-17"
build: performance
build_type: Release
test_threads: 2
cxx_flags: "-stdlib=libc++"

- name: "Performance gcc11"
compiler: "gcc-11"
build: performance
Expand Down
4 changes: 3 additions & 1 deletion test/include/seqan3/test/performance/units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ inline benchmark::Counter bytes_per_second(size_t bytes)
template <typename sequences_range_t>
inline size_t pairwise_cell_updates(sequences_range_t const & sequences_range, [[maybe_unused]] auto && align_cfg)
{
using config_t = std::remove_cvref_t<decltype(align_cfg)>;

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<seqan3::align_cfg::band_fixed_size>())
if constexpr (config_t::template exists<seqan3::align_cfg::band_fixed_size>())
{
using std::get;
auto const band_cfg = get<seqan3::align_cfg::band_fixed_size>(align_cfg);
Expand Down
10 changes: 5 additions & 5 deletions test/performance/io/format_vienna_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<seqan3::rna4>(474, 0, 0);
auto const sequence = rna_sequence | seqan3::views::to_char | seqan3::ranges::to<std::string>();
static std::string const header{"seq foobar blobber"};
static inline auto const rna_sequence = seqan3::test::generate_sequence<seqan3::rna4>(474, 0, 0);
static auto const sequence = rna_sequence | seqan3::views::to_char | seqan3::ranges::to<std::string>();

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++)
Expand Down
13 changes: 12 additions & 1 deletion test/performance/io/lowlevel_stream_input_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,53 +47,64 @@ 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<char> it{s};
std::istream_iterator<char> 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<char> it{s};
std::istreambuf_iterator<char> 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<char> it{*s.rdbuf()};
std::default_sentinel_t e{};

for (; it != e; ++it)
c += *it;

benchmark::DoNotOptimize(c);
}
}
#ifdef SEQAN3_HAS_SEQAN2
else if constexpr (id == tag::seqan2_stream_it)
{
for (auto _ : state)
{
char c{};
std::ifstream s{filename, std::ios::binary};
auto it = seqan2::Iter<std::ifstream, seqan2::StreamIterator<seqan2::Input>>{s};

for (; !seqan2::atEnd(it); ++it)
c += *it;

benchmark::DoNotOptimize(c);
}
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions test/performance/range/container_assignment_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static constexpr void resize(container_t & container,
}
#endif // SEQAN3_HAS_SEQAN2

template <tag id, template <typename> typename container_t, typename alphabet_t>
template <tag id, template <typename, typename...> typename container_t, typename alphabet_t, typename... args>
static void assign(benchmark::State & state)
{
auto random_sequence = []() constexpr
Expand All @@ -99,10 +99,10 @@ static void assign(benchmark::State & state)
#endif // SEQAN3_HAS_SEQAN2
}();

container_t<alphabet_t> from{};
container_t<alphabet_t, args...> from{};
resize(from, vector_size);
std::copy(std::ranges::begin(random_sequence), std::ranges::end(random_sequence), std::ranges::begin(from));
container_t<alphabet_t> to{};
container_t<alphabet_t, args...> to{};
resize(to, vector_size);
assignment_functor<id> fn{};

Expand Down
4 changes: 2 additions & 2 deletions test/performance/range/container_push_back_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ using small_vec = seqan3::small_vector<t, 10'000>;
// push_back
// ============================================================================

template <template <typename> typename container_t, typename alphabet_t>
template <template <typename, typename...> typename container_t, typename alphabet_t, typename... args>
void push_back(benchmark::State & state)
{
alphabet_t letter{};

for (auto _ : state)
{
container_t<alphabet_t> container;
container_t<alphabet_t, args...> container;
for (size_t i = 0; i < 10'000; ++i)
container.push_back(letter);
benchmark::DoNotOptimize(letter = container.back());
Expand Down
13 changes: 8 additions & 5 deletions test/performance/range/container_seq_read_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ using small_vec = seqan3::small_vector<t, 10'000>;
// sequential_read
// ============================================================================

template <template <typename> typename container_t, typename alphabet_t, bool const_qualified = false>
template <template <typename, typename...> typename container_t,
typename alphabet_t,
bool const_qualified = false,
typename... args>
void sequential_read(benchmark::State & state)
{
container_t<alphabet_t> container = []()
container_t<alphabet_t, args...> container = []()
{
auto container = seqan3::test::generate_sequence<alphabet_t>(10'000, 0, 0);
return container_t<alphabet_t>(container.begin(), container.end());
return container_t<alphabet_t, args...>(container.begin(), container.end());
}();

using container_reference_t =
std::conditional_t<const_qualified, container_t<alphabet_t> const &, container_t<alphabet_t> &>;
using container_reference_t = std::
conditional_t<const_qualified, container_t<alphabet_t, args...> const &, container_t<alphabet_t, args...> &>;

container_reference_t container_reference{container};

Expand Down
6 changes: 3 additions & 3 deletions test/performance/range/container_seq_write_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ using small_vec = seqan3::small_vector<t, 10'000>;
// sequential_write
// ============================================================================

template <template <typename> typename container_t, typename alphabet_t>
template <template <typename, typename...> typename container_t, typename alphabet_t, typename... args>
void sequential_write(benchmark::State & state)
{
container_t<alphabet_t> container = []()
container_t<alphabet_t, args...> container = []()
{
auto container = seqan3::test::generate_sequence<alphabet_t>(10'000, 0, 0);
return container_t<alphabet_t>(container.begin(), container.end());
return container_t<alphabet_t, args...>(container.begin(), container.end());
}();

alphabet_t letter{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void compute_minimisers(benchmark::State & state)
// Use random seed to randomise order on forward strand.
auto forward = seq | seqan3::views::kmer_hash(shape)
| std::views::transform(
[seed](uint64_t const i)
[](uint64_t const i)
{
return i ^ seed;
});
Comment on lines -101 to 104
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is seed available now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's implicitly captured because it's const.

Expand All @@ -107,7 +107,7 @@ void compute_minimisers(benchmark::State & state)
| std::views::reverse // Reverse order.
| seqan3::views::kmer_hash(shape) // Get hash values.
| std::views::transform(
[seed](uint64_t const i)
[](uint64_t const i)
{
return i ^ seed;
}) // Randomise.
Expand All @@ -131,7 +131,7 @@ void compute_minimisers(benchmark::State & state)
while (subrange_end != end(both))
{
++subrange_end; // Extends the subrange to `w - shape.size()+1`
auto h = *std::min_element(subrange_begin, subrange_end);
auto h = *std::ranges::min_element(subrange_begin, subrange_end);

++subrange_begin; // Move the beginning one forward
benchmark::DoNotOptimize(sum += h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct for_loop_with_simd_add_benchmark
void operator()(index_simd_t & count) const
{
index_simd_t simd_index{};
for (size_t index = 0; index < end_index; ++index, ++simd_index)
for (size_t index = 0; index < end_index; ++index, simd_index += 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ did not work? seems so basic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Libc++ says it implements ++ for Simd types, but it doesn't work :D

count += simd_index;
}
};
Expand Down
2 changes: 2 additions & 0 deletions test/seqan3-test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ endif ()
if (NOT TARGET seqan3::test::performance)
add_library (seqan3_test_performance INTERFACE)
target_link_libraries (seqan3_test_performance INTERFACE "seqan3::test" "benchmark_main" "benchmark")
# std::views::join is experimental in libc++
target_compile_definitions (seqan3_test_performance INTERFACE _LIBCPP_ENABLE_EXPERIMENTAL)

if (SEQAN3_BENCHMARK_ALIGN_LOOPS)
target_compile_options (seqan3_test_performance INTERFACE "-falign-loops=32")
Expand Down