generated from seqan/library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from eseiler/misc/perf
[MISC] Improve bulk_contains performance
- Loading branch information
Showing
6 changed files
with
297 additions
and
27 deletions.
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(); |
5caf0e3
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.
Successfully deployed to the following URLs:
hibf – ./
hibf.vercel.app
hibf-seqan.vercel.app
hibf-git-main-seqan.vercel.app