Skip to content

Commit

Permalink
Merge pull request #71 from eseiler/infra/benchmark
Browse files Browse the repository at this point in the history
[INFRA] Add bin benchmark
  • Loading branch information
eseiler authored Aug 26, 2021
2 parents ef8957d + e2ee71c commit 12c6b50
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 13 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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}")
3 changes: 3 additions & 0 deletions test/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake_minimum_required (VERSION 3.8)

add_cli_test (bin_influence_benchmark.cpp)
58 changes: 58 additions & 0 deletions test/benchmark/bin_influence_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -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 <benchmark/benchmark.h>

#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/utility/views/slice.hpp>

#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
#include <seqan3/test/performance/sequence_generator.hpp>

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<seqan3::dna4> const genome{seqan3::test::generate_sequence<seqan3::dna4>(genome_size, 0, 0)};
static std::vector<std::vector<seqan3::dna4>> const reads{[] (auto const & genome) {
std::vector<std::vector<seqan3::dna4>> result(read_count);
size_t i{};
for (auto && read_start : seqan3::test::generate_numeric_sequence<size_t>(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<size_t>(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<seqan3::data_layout::uncompressed> 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<uint16_t>();
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();

0 comments on commit 12c6b50

Please sign in to comment.