Skip to content

Commit 12c6b50

Browse files
authored
Merge pull request #71 from eseiler/infra/benchmark
[INFRA] Add bin benchmark
2 parents ef8957d + e2ee71c commit 12c6b50

File tree

7 files changed

+79
-5
lines changed

7 files changed

+79
-5
lines changed

.github/workflows/ci_linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
run: |
9797
mkdir build
9898
cd build
99-
cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
99+
cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DRAPTOR_NATIVE_BUILD=OFF
100100
101101
- name: Build tests
102102
env:

.github/workflows/ci_macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
run: |
8484
mkdir build
8585
cd build
86-
cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
86+
cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DRAPTOR_NATIVE_BUILD=OFF
8787
8888
- name: Build application
8989
env:

.github/workflows/ci_misc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
run: |
9292
mkdir build
9393
cd build
94-
cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
94+
cmake ../raptor -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DRAPTOR_NATIVE_BUILD=OFF
9595
9696
- name: Build tests
9797
if: ${{!matrix.skip_build_tests}}

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,7 @@ add_subdirectory (doc EXCLUDE_FROM_ALL)
9797

9898
## TEST
9999

100+
set (RAPTOR_ENABLE_BENCHMARK OFF CACHE BOOL "Compile benchmarks as cli tests.")
101+
100102
enable_testing ()
101103
add_subdirectory (test EXCLUDE_FROM_ALL)

test/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ macro (add_app_test test_filename test_alternative)
5353
target_link_libraries (${target} "${PROJECT_NAME}_lib" seqan3::seqan3 gtest gtest_main)
5454

5555
# Make seqan3::test available for both cli and api tests.
56-
target_include_directories(${target} PUBLIC "${SEQAN3_CLONE_DIR}/test/include")
57-
target_include_directories(${target} PUBLIC "${SEQAN3_TEST_CLONE_DIR}/googletest/include/")
56+
target_include_directories (${target} PUBLIC "${SEQAN3_CLONE_DIR}/test/include")
57+
target_include_directories (${target} PUBLIC "${SEQAN3_TEST_CLONE_DIR}/googletest/include/")
5858

5959
# Add the test to its general target (cli or api).
6060
if (${test_alternative} STREQUAL "CLI_TEST")
6161
add_dependencies (${target} "${PROJECT_NAME}") # cli test needs the application executable
6262
add_dependencies (cli_test ${target})
63+
if (RAPTOR_ENABLE_BENCHMARK)
64+
target_include_directories (${target} PUBLIC "${SEQAN3_BENCHMARK_CLONE_DIR}/include/")
65+
target_link_libraries (${target} gbenchmark)
66+
endif ()
6367
elseif (${test_alternative} STREQUAL "API_TEST")
6468
add_dependencies (api_test ${target})
6569
endif ()
@@ -94,4 +98,11 @@ add_subdirectory (api)
9498
add_subdirectory (cli)
9599
add_subdirectory (coverage)
96100

101+
if (RAPTOR_ENABLE_BENCHMARK)
102+
set (SEQAN3_BENCHMARK_CLONE_DIR "${PROJECT_BINARY_DIR}/vendor/benchmark")
103+
include ("${SEQAN3_CLONE_DIR}/test/cmake/seqan3_require_benchmark.cmake")
104+
seqan3_require_benchmark ()
105+
add_subdirectory (benchmark)
106+
endif ()
107+
97108
message (STATUS "${FontBold}You can run `make test` to build and run tests.${FontReset}")

test/benchmark/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake_minimum_required (VERSION 3.8)
2+
3+
add_cli_test (bin_influence_benchmark.cpp)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// -----------------------------------------------------------------------------------------------------
2+
// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3+
// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
4+
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5+
// shipped with this file and also available at: https://github.com/seqan/raptor/blob/master/LICENSE.md
6+
// -----------------------------------------------------------------------------------------------------
7+
8+
#include <benchmark/benchmark.h>
9+
10+
#include <seqan3/alphabet/nucleotide/dna4.hpp>
11+
#include <seqan3/utility/views/slice.hpp>
12+
13+
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
14+
#include <seqan3/search/views/kmer_hash.hpp>
15+
#include <seqan3/test/performance/sequence_generator.hpp>
16+
17+
static constexpr size_t const genome_size{5000}; // 4'300'000'000
18+
static constexpr size_t const read_size{100};
19+
static constexpr size_t const read_count{1000}; // 1'000'000
20+
static constexpr size_t const ibf_size{8'388'608/*=1MiB*/}; // 34'359'738'368/*=4GiB*/
21+
22+
static std::vector<seqan3::dna4> const genome{seqan3::test::generate_sequence<seqan3::dna4>(genome_size, 0, 0)};
23+
static std::vector<std::vector<seqan3::dna4>> const reads{[] (auto const & genome) {
24+
std::vector<std::vector<seqan3::dna4>> result(read_count);
25+
size_t i{};
26+
for (auto && read_start : seqan3::test::generate_numeric_sequence<size_t>(read_count, 0, genome_size - read_size + 1, 0))
27+
{
28+
auto v = genome | seqan3::views::slice(read_start, read_start + read_size);
29+
result[i++].assign(v.begin(), v.end());
30+
}
31+
return result;
32+
} (genome)};
33+
34+
static void search_benchmark(benchmark::State & state)
35+
{
36+
size_t const bin_count = static_cast<size_t>(state.range(0));
37+
size_t const hash_num{2u};
38+
size_t const bin_size{ibf_size / bin_count};
39+
size_t const chunk_size{(genome_size + bin_count - 1) / bin_count};
40+
41+
seqan3::interleaved_bloom_filter<seqan3::data_layout::uncompressed> ibf{seqan3::bin_count{bin_count},
42+
seqan3::bin_size{bin_size},
43+
seqan3::hash_function_count{hash_num}};
44+
45+
size_t bin_counter{};
46+
for (auto && sequence : genome | seqan3::views::chunk(chunk_size))
47+
for (auto && hash : sequence | seqan3::views::kmer_hash(seqan3::ungapped{19u}))
48+
ibf.emplace(hash, seqan3::bin_index{bin_counter++});
49+
50+
auto agent = ibf.counting_agent<uint16_t>();
51+
for (auto _ : state)
52+
for (auto && query : reads)
53+
benchmark::DoNotOptimize(agent.bulk_count(query | seqan3::views::kmer_hash(seqan3::ungapped{19u})));
54+
}
55+
56+
BENCHMARK(search_benchmark)->RangeMultiplier(2)->Range(64, 65536);
57+
58+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)