generated from seqan/library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
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
[MISC] Improve bulk_contains performance #45
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
342ba27
[INFRA] Find any Google {Test/Benchmark} version
eseiler 449798b
[MISC] Improve bulk_contains performance
eseiler 01dc4f5
[INFRA] Ignore IntelLLVM warning about failed vectorization when not …
eseiler d16026b
[MISC] Ignore switch/case for gcov
eseiler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hibf_benchmark (interleaved_bloom_filter_benchmark.cpp) |
175 changes: 175 additions & 0 deletions
175
test/performance/ibf/interleaved_bloom_filter_benchmark.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// ----------------------------------------------------------------------------------------------------- | ||
// Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin | ||
// Copyright (c) 2016-2023, 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/seqan3/blob/master/LICENSE.md | ||
// ----------------------------------------------------------------------------------------------------- | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <hibf/contrib/std/to.hpp> | ||
#include <hibf/contrib/std/zip_view.hpp> | ||
#include <hibf/interleaved_bloom_filter.hpp> | ||
|
||
inline benchmark::Counter hashes_per_second(size_t const count) | ||
{ | ||
return benchmark::Counter(count, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000); | ||
} | ||
|
||
#if 1 | ||
static void arguments(benchmark::internal::Benchmark * b) | ||
{ | ||
// Total size: 1MiB | ||
// bins, bin_size, hash_num, sequence_length | ||
b->Args({64, 1LL << 17, 2, 1LL << 17}); | ||
b->Args({128, 1LL << 16, 2, 1LL << 17}); | ||
b->Args({192, 1LL << 16, 2, 1LL << 17}); | ||
b->Args({256, 1LL << 15, 2, 1LL << 17}); | ||
b->Args({1024, 1LL << 10, 2, 1LL << 17}); | ||
} | ||
#else | ||
static void arguments(benchmark::internal::Benchmark * b) | ||
{ | ||
// Total size: 1GiB | ||
// bins, bin_size, hash_num, sequence_length | ||
b->Args({64, 1LL << 27, 2, 1LL << 27}); | ||
b->Args({128, 1LL << 26, 2, 1LL << 27}); | ||
b->Args({192, 1LL << 26, 2, 1LL << 27}); | ||
b->Args({256, 1LL << 25, 2, 1LL << 27}); | ||
b->Args({1024, 1LL << 20, 2, 1LL << 27}); | ||
} | ||
#endif | ||
|
||
auto set_up(::benchmark::State const & state) | ||
{ | ||
size_t const bins = state.range(0); | ||
size_t const bits = state.range(1); | ||
size_t const hash_num = state.range(2); | ||
size_t const sequence_length = state.range(3); | ||
|
||
auto generate = [sequence_length](size_t const max_value = std::numeric_limits<size_t>::max()) | ||
{ | ||
auto generator = [max_value]() | ||
{ | ||
std::uniform_int_distribution<size_t> distr{0u, max_value}; | ||
std::mt19937_64 engine{0ULL}; | ||
return distr(engine); | ||
}; | ||
std::vector<size_t> result(sequence_length); | ||
|
||
std::ranges::generate(result, generator); | ||
return result; | ||
}; | ||
|
||
std::vector<size_t> const bin_indices{generate(bins - 1)}; | ||
std::vector<size_t> const hash_values{generate()}; | ||
|
||
hibf::interleaved_bloom_filter ibf{hibf::bin_count{bins}, | ||
hibf::bin_size{bits}, | ||
hibf::hash_function_count{hash_num}}; | ||
|
||
return std::make_tuple(bin_indices, hash_values, ibf); | ||
} | ||
|
||
void emplace_benchmark(::benchmark::State & state) | ||
{ | ||
auto && [bin_indices, hash_values, ibf] = set_up(state); | ||
|
||
for (auto _ : state) | ||
{ | ||
for (auto [hash, bin] : seqan::std::views::zip(hash_values, bin_indices)) | ||
ibf.emplace(hash, hibf::bin_index{bin}); | ||
} | ||
|
||
state.counters["hashes/sec"] = hashes_per_second(std::ranges::size(hash_values)); | ||
} | ||
|
||
void clear_benchmark(::benchmark::State & state) | ||
{ | ||
auto && [bin_indices, hash_values, ibf] = set_up(state); | ||
(void)bin_indices; | ||
(void)hash_values; | ||
|
||
std::vector<hibf::bin_index> bin_range = std::views::iota(0u, static_cast<size_t>(state.range(0))) | ||
| std::views::transform( | ||
[](size_t i) | ||
{ | ||
return hibf::bin_index{i}; | ||
}) | ||
| seqan::std::ranges::to<std::vector>(); | ||
|
||
for (auto _ : state) | ||
{ | ||
for (auto bin : bin_range) | ||
ibf.clear(bin); | ||
} | ||
|
||
state.counters["bins/sec"] = hashes_per_second(std::ranges::size(bin_range)); | ||
} | ||
|
||
void clear_range_benchmark(::benchmark::State & state) | ||
{ | ||
auto && [bin_indices, hash_values, ibf] = set_up(state); | ||
(void)bin_indices; | ||
(void)hash_values; | ||
|
||
std::vector<hibf::bin_index> bin_range = std::views::iota(0u, static_cast<size_t>(state.range(0))) | ||
| std::views::transform( | ||
[](size_t i) | ||
{ | ||
return hibf::bin_index{i}; | ||
}) | ||
| seqan::std::ranges::to<std::vector>(); | ||
|
||
for (auto _ : state) | ||
{ | ||
ibf.clear(bin_range); | ||
} | ||
|
||
state.counters["bins/sec"] = hashes_per_second(std::ranges::size(bin_range)); | ||
} | ||
|
||
void bulk_contains_benchmark(::benchmark::State & state) | ||
{ | ||
auto && [bin_indices, hash_values, ibf] = set_up(state); | ||
|
||
for (auto [hash, bin] : seqan::std::views::zip(hash_values, bin_indices)) | ||
ibf.emplace(hash, hibf::bin_index{bin}); | ||
|
||
auto agent = ibf.membership_agent(); | ||
for (auto _ : state) | ||
{ | ||
for (auto hash : hash_values) | ||
{ | ||
[[maybe_unused]] auto & res = agent.bulk_contains(hash); | ||
benchmark::ClobberMemory(); | ||
} | ||
} | ||
|
||
state.counters["hashes/sec"] = hashes_per_second(std::ranges::size(hash_values)); | ||
} | ||
|
||
void bulk_count_benchmark(::benchmark::State & state) | ||
{ | ||
auto && [bin_indices, hash_values, ibf] = set_up(state); | ||
|
||
for (auto [hash, bin] : seqan::std::views::zip(hash_values, bin_indices)) | ||
ibf.emplace(hash, hibf::bin_index{bin}); | ||
|
||
auto agent = ibf.counting_agent(); | ||
for (auto _ : state) | ||
{ | ||
[[maybe_unused]] auto & res = agent.bulk_count(hash_values); | ||
benchmark::ClobberMemory(); | ||
} | ||
|
||
state.counters["hashes/sec"] = hashes_per_second(std::ranges::size(hash_values)); | ||
} | ||
|
||
BENCHMARK(emplace_benchmark)->Apply(arguments); | ||
BENCHMARK(clear_benchmark)->Apply(arguments); | ||
BENCHMARK(clear_range_benchmark)->Apply(arguments); | ||
BENCHMARK(bulk_contains_benchmark)->Apply(arguments); | ||
BENCHMARK(bulk_count_benchmark)->Apply(arguments); | ||
|
||
BENCHMARK_MAIN(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auch wegen der Auto-vectorisierung? Denn eigentlich sollten asserts im release mode ja sowieso wegcompiliert werden oder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to actually assert in Debug mode, and not just declare it as UB. No idea what happens (guaranteed) when I have both
__builtin_unreachable()
and an assert :)