diff --git a/.github/workflows/ci_linux.yml b/.github/workflows/ci_linux.yml index 2339d8e1..a268b01b 100644 --- a/.github/workflows/ci_linux.yml +++ b/.github/workflows/ci_linux.yml @@ -96,7 +96,7 @@ jobs: run: | mkdir build cd build - cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" + cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DRAPTOR_NATIVE_BUILD=OFF - name: Build tests env: diff --git a/.github/workflows/ci_macos.yml b/.github/workflows/ci_macos.yml index 8e1d1a58..2303537f 100644 --- a/.github/workflows/ci_macos.yml +++ b/.github/workflows/ci_macos.yml @@ -83,7 +83,7 @@ jobs: run: | mkdir build cd build - cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" + cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DRAPTOR_NATIVE_BUILD=OFF - name: Build application env: diff --git a/.github/workflows/ci_misc.yml b/.github/workflows/ci_misc.yml index 475909de..038a3444 100644 --- a/.github/workflows/ci_misc.yml +++ b/.github/workflows/ci_misc.yml @@ -91,7 +91,7 @@ jobs: run: | mkdir build cd build - cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" + cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DRAPTOR_NATIVE_BUILD=OFF - name: Build tests if: ${{!matrix.skip_build_tests}} diff --git a/CMakeLists.txt b/CMakeLists.txt index bcba0c50..808233d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,5 +97,7 @@ add_subdirectory (doc EXCLUDE_FROM_ALL) ## TEST +set (RAPTOR_ENABLE_BENCHMARK OFF CACHE BOOL "Compile benchmarks as cli tests.") + enable_testing () add_subdirectory (test EXCLUDE_FROM_ALL) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 23723903..6a398ac8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -53,13 +53,17 @@ macro (add_app_test test_filename test_alternative) target_link_libraries (${target} "${PROJECT_NAME}_lib" seqan3::seqan3 gtest gtest_main) # Make seqan3::test available for both cli and api tests. - target_include_directories(${target} PUBLIC "${SEQAN3_CLONE_DIR}/test/include") - target_include_directories(${target} PUBLIC "${SEQAN3_TEST_CLONE_DIR}/googletest/include/") + target_include_directories (${target} PUBLIC "${SEQAN3_CLONE_DIR}/test/include") + target_include_directories (${target} PUBLIC "${SEQAN3_TEST_CLONE_DIR}/googletest/include/") # Add the test to its general target (cli or api). if (${test_alternative} STREQUAL "CLI_TEST") add_dependencies (${target} "${PROJECT_NAME}") # cli test needs the application executable add_dependencies (cli_test ${target}) + if (RAPTOR_ENABLE_BENCHMARK) + target_include_directories (${target} PUBLIC "${SEQAN3_BENCHMARK_CLONE_DIR}/include/") + target_link_libraries (${target} gbenchmark) + endif () elseif (${test_alternative} STREQUAL "API_TEST") add_dependencies (api_test ${target}) endif () @@ -94,4 +98,11 @@ add_subdirectory (api) add_subdirectory (cli) add_subdirectory (coverage) +if (RAPTOR_ENABLE_BENCHMARK) + set (SEQAN3_BENCHMARK_CLONE_DIR "${PROJECT_BINARY_DIR}/vendor/benchmark") + include ("${SEQAN3_CLONE_DIR}/test/cmake/seqan3_require_benchmark.cmake") + seqan3_require_benchmark () + add_subdirectory (benchmark) +endif () + message (STATUS "${FontBold}You can run `make test` to build and run tests.${FontReset}") diff --git a/test/benchmark/CMakeLists.txt b/test/benchmark/CMakeLists.txt new file mode 100644 index 00000000..85489b3f --- /dev/null +++ b/test/benchmark/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required (VERSION 3.8) + +add_cli_test (bin_influence_benchmark.cpp) diff --git a/test/benchmark/bin_influence_benchmark.cpp b/test/benchmark/bin_influence_benchmark.cpp new file mode 100644 index 00000000..41930886 --- /dev/null +++ b/test/benchmark/bin_influence_benchmark.cpp @@ -0,0 +1,58 @@ +// ----------------------------------------------------------------------------------------------------- +// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin +// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik +// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License +// shipped with this file and also available at: https://github.com/seqan/raptor/blob/master/LICENSE.md +// ----------------------------------------------------------------------------------------------------- + +#include + +#include +#include + +#include +#include +#include + +static constexpr size_t const genome_size{5000}; // 4'300'000'000 +static constexpr size_t const read_size{100}; +static constexpr size_t const read_count{1000}; // 1'000'000 +static constexpr size_t const ibf_size{8'388'608/*=1MiB*/}; // 34'359'738'368/*=4GiB*/ + +static std::vector const genome{seqan3::test::generate_sequence(genome_size, 0, 0)}; +static std::vector> const reads{[] (auto const & genome) { + std::vector> result(read_count); + size_t i{}; + for (auto && read_start : seqan3::test::generate_numeric_sequence(read_count, 0, genome_size - read_size + 1, 0)) + { + auto v = genome | seqan3::views::slice(read_start, read_start + read_size); + result[i++].assign(v.begin(), v.end()); + } + return result; + } (genome)}; + +static void search_benchmark(benchmark::State & state) +{ + size_t const bin_count = static_cast(state.range(0)); + size_t const hash_num{2u}; + size_t const bin_size{ibf_size / bin_count}; + size_t const chunk_size{(genome_size + bin_count - 1) / bin_count}; + + seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{bin_count}, + seqan3::bin_size{bin_size}, + seqan3::hash_function_count{hash_num}}; + + size_t bin_counter{}; + for (auto && sequence : genome | seqan3::views::chunk(chunk_size)) + for (auto && hash : sequence | seqan3::views::kmer_hash(seqan3::ungapped{19u})) + ibf.emplace(hash, seqan3::bin_index{bin_counter++}); + + auto agent = ibf.counting_agent(); + for (auto _ : state) + for (auto && query : reads) + benchmark::DoNotOptimize(agent.bulk_count(query | seqan3::views::kmer_hash(seqan3::ungapped{19u}))); +} + +BENCHMARK(search_benchmark)->RangeMultiplier(2)->Range(64, 65536); + +BENCHMARK_MAIN();