Skip to content

Commit 19b7364

Browse files
committed
Further simplify benchmarks. Add benchmarks for unordered pixel iteration
1 parent 0065c8b commit 19b7364

File tree

10 files changed

+174
-228
lines changed

10 files changed

+174
-228
lines changed

benchmark/interaction_fetching/common.hpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@
2121
#include "hictk/chromosome.hpp"
2222
#include "hictk/reference.hpp"
2323

24-
// NOLINTBEGIN(*-avoid-magic-numbers)
25-
struct Params {
26-
std::string_view label{};
27-
bool cis{};
28-
29-
double avg_height{1.0e6};
30-
double avg_width{1.0e6};
31-
double height_std{250.0e3};
32-
double width_std{250.0e3};
33-
std::size_t num_queries{1};
34-
hictk::balancing::Method normalization{hictk::balancing::Method::NONE()};
35-
std::uint64_t seed{123456789};
36-
};
37-
// NOLINTEND(*-avoid-magic-numbers)
38-
3924
[[nodiscard]] inline std::pair<std::string, std::string> generate_query(
4025
std::mt19937_64& rand_eng, const hictk::Chromosome& chrom1, const hictk::Chromosome& chrom2,
4126
double avg_height, double avg_width, double height_std, double width_std) {
@@ -158,3 +143,26 @@ template <typename N, typename File>
158143
// clang-format on
159144
return i;
160145
}
146+
147+
template <typename N, typename File>
148+
[[nodiscard]] inline std::ptrdiff_t count_nnz_unsorted(
149+
const File& file, std::string_view range1, std::string_view range2,
150+
const hictk::balancing::Method& normalization) {
151+
const auto sel = file.fetch(range1, range2, normalization);
152+
153+
return std::distance(sel.template begin<N>(false), sel.template end<N>());
154+
}
155+
156+
template <typename N, typename File>
157+
[[nodiscard]] inline std::ptrdiff_t count_nnz_unsorted(
158+
const File& file, std::size_t max_num_pixels, const hictk::balancing::Method& normalization) {
159+
const auto sel = file.fetch(normalization);
160+
auto first = sel.template begin<N>(false);
161+
auto last = sel.template end<N>();
162+
163+
std::ptrdiff_t i{};
164+
// clang-format off
165+
while (++first != last && ++i != static_cast<std::ptrdiff_t>(max_num_pixels)); // NOLINT
166+
// clang-format on
167+
return i;
168+
}

benchmark/interaction_fetching/cooler_cis_queries.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,28 @@ static constexpr std::string_view range_small{"chr2L:5,000,000-5,100,000"};
2727
static constexpr std::string_view range_medium{"chr2L:6,000,000-7,000,000"};
2828
static constexpr std::string_view range_large{"chr2L:10,000,000-15,000,000"};
2929

30-
TEST_CASE("cooler::File::fetch (cis; uint32)") {
31-
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
32-
test_file.string(), resolutions.back()))
33-
.chromosomes();
34-
for (const auto& res : resolutions) {
35-
for (const auto& range : {range_small, range_medium, range_large}) {
36-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), range, res))
37-
(Catch::Benchmark::Chronometer meter) {
38-
const cooler::File clr(
39-
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
40-
meter.measure([&clr, &range]() {
41-
return count_nnz<std::uint32_t>(clr, range, range, balancing::Method::NONE());
42-
});
43-
};
44-
}
45-
}
30+
template <typename N>
31+
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
32+
std::string_view range, const balancing::Method& normalization) {
33+
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp; {}"), range, resolution,
34+
std::is_integral_v<N> ? "int" : "fp"))
35+
(Catch::Benchmark::Chronometer meter) {
36+
const cooler::File clr(
37+
fmt::format(FMT_STRING("{}::/resolutions/{}"), path.string(), resolution));
38+
meter.measure([&clr, &range, &normalization]() {
39+
return count_nnz<N>(clr, range, range, normalization);
40+
});
41+
};
4642
}
4743

48-
TEST_CASE("cooler::File::fetch (cis; double)") {
44+
TEST_CASE("cooler::File::fetch (cis)") {
4945
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
5046
test_file.string(), resolutions.back()))
5147
.chromosomes();
5248
for (const auto& res : resolutions) {
5349
for (const auto& range : {range_small, range_medium, range_large}) {
54-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), range, res))
55-
(Catch::Benchmark::Chronometer meter) {
56-
const cooler::File clr(
57-
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
58-
meter.measure([&clr, &range]() {
59-
return count_nnz<double>(clr, range, range, balancing::Method::KR());
60-
});
61-
};
50+
run_benchmark<std::uint32_t>(test_file, res, range, balancing::Method::NONE());
51+
run_benchmark<double>(test_file, res, range, balancing::Method::KR());
6252
}
6353
}
6454
}

benchmark/interaction_fetching/cooler_gw_queries.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,26 @@ static const std::filesystem::path test_file{"test/data/integration_tests/4DNFIZ
2121
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
2222
100000, 250000, 500000, 1000000, 2500000};
2323

24-
TEST_CASE("cooler::File::fetch (gw; uint32)") {
25-
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
26-
test_file.string(), resolutions.back()))
27-
.chromosomes();
28-
for (const auto& res : resolutions) {
29-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}bp"), res))
30-
(Catch::Benchmark::Chronometer meter) {
31-
const cooler::File clr(
32-
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
33-
meter.measure([&clr]() {
34-
return count_nnz<std::uint32_t>(clr, 10'000'000, balancing::Method::NONE());
35-
});
36-
};
37-
}
24+
template <typename N>
25+
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
26+
const balancing::Method& normalization) {
27+
BENCHMARK_ADVANCED(
28+
fmt::format(FMT_STRING("{}bp; {}"), resolution, std::is_integral_v<N> ? "int" : "fp"))
29+
(Catch::Benchmark::Chronometer meter) {
30+
const cooler::File clr(
31+
fmt::format(FMT_STRING("{}::/resolutions/{}"), path.string(), resolution));
32+
meter.measure(
33+
[&clr, &normalization]() { return count_nnz<N>(clr, 10'000'000, normalization); });
34+
};
3835
}
3936

40-
TEST_CASE("cooler::File::fetch (gw; double)") {
37+
TEST_CASE("cooler::File::fetch (gw)") {
4138
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
4239
test_file.string(), resolutions.back()))
4340
.chromosomes();
4441
for (const auto& res : resolutions) {
45-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}bp"), res))
46-
(Catch::Benchmark::Chronometer meter) {
47-
const cooler::File clr(
48-
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
49-
meter.measure(
50-
[&clr]() { return count_nnz<std::uint32_t>(clr, 10'000'000, balancing::Method::KR()); });
51-
};
42+
run_benchmark<std::uint32_t>(test_file, res, balancing::Method::NONE());
43+
run_benchmark<double>(test_file, res, balancing::Method::KR());
5244
}
5345
}
5446
// NOLINTEND(*-avoid-magic-numbers, cert-err58-cpp, readability-function-cognitive-complexity)

benchmark/interaction_fetching/cooler_trans_queries.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,30 @@ static constexpr std::pair<std::string_view, std::string_view> range_medium{
3232
static constexpr std::pair<std::string_view, std::string_view> range_large{
3333
"chr2L:15,000,000-20,000,000", "chrX:15,000,000-20,000,000"};
3434

35-
TEST_CASE("cooler::File::fetch (trans; uint32)") {
36-
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
37-
test_file.string(), resolutions.back()))
38-
.chromosomes();
39-
for (const auto& res : resolutions) {
40-
for (const auto& query : {range_small, range_medium, range_large}) {
41-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
42-
(Catch::Benchmark::Chronometer meter) {
43-
const cooler::File clr(
44-
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
45-
meter.measure([&clr, range1 = query.first, range2 = query.second]() {
46-
return count_nnz<std::uint32_t>(clr, range1, range2, balancing::Method::NONE());
47-
});
48-
};
49-
}
50-
}
35+
template <typename N>
36+
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
37+
std::string_view range1, std::string_view range2,
38+
const balancing::Method& normalization) {
39+
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp; {}"), range1, range2, resolution,
40+
std::is_integral_v<N> ? "int" : "fp"))
41+
(Catch::Benchmark::Chronometer meter) {
42+
const cooler::File clr(
43+
fmt::format(FMT_STRING("{}::/resolutions/{}"), path.string(), resolution));
44+
meter.measure([&clr, &range1, &range2, &normalization]() {
45+
return count_nnz<N>(clr, range1, range2, normalization);
46+
});
47+
};
5148
}
5249

53-
TEST_CASE("cooler::File::fetch (trans; double)") {
50+
TEST_CASE("cooler::File::fetch (trans)") {
5451
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
5552
test_file.string(), resolutions.back()))
5653
.chromosomes();
5754
for (const auto& res : resolutions) {
5855
for (const auto& query : {range_small, range_medium, range_large}) {
59-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
60-
(Catch::Benchmark::Chronometer meter) {
61-
const cooler::File clr(
62-
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
63-
meter.measure([&clr, range1 = query.first, range2 = query.second]() {
64-
return count_nnz<double>(clr, range1, range2, balancing::Method::KR());
65-
});
66-
};
56+
run_benchmark<std::uint32_t>(test_file, res, query.first, query.second,
57+
balancing::Method::NONE());
58+
run_benchmark<double>(test_file, res, query.first, query.second, balancing::Method::KR());
6759
}
6860
}
6961
}

benchmark/interaction_fetching/file_cis_queries.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,28 @@ static constexpr std::string_view range_small{"chr2L:5,000,000-5,100,000"};
3030
static constexpr std::string_view range_medium{"chr2L:6,000,000-7,000,000"};
3131
static constexpr std::string_view range_large{"chr2L:10,000,000-15,000,000"};
3232

33-
TEST_CASE("File::fetch (cis; uint32)") {
34-
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
35-
test_file1.string(), resolutions.back()))
36-
.chromosomes();
37-
38-
for (const auto& path : {test_file1, test_file2, test_file3}) {
39-
for (const auto& res : resolutions) {
40-
for (const auto& range : {range_small, range_medium, range_large}) {
41-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), range, res))
42-
(Catch::Benchmark::Chronometer meter) {
43-
const File f(path.string(), res);
44-
meter.measure([&f, &range]() {
45-
return count_nnz<std::uint32_t>(f, range, range, balancing::Method::NONE());
46-
});
47-
};
48-
}
49-
}
50-
}
33+
template <typename N>
34+
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
35+
std::string_view range, const balancing::Method& normalization) {
36+
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp; {}"), path.extension(), range,
37+
resolution, std::is_integral_v<N> ? "int" : "fp"))
38+
(Catch::Benchmark::Chronometer meter) {
39+
const File f(path.string(), resolution);
40+
meter.measure(
41+
[&f, &range, &normalization]() { return count_nnz<N>(f, range, range, normalization); });
42+
};
5143
}
5244

53-
TEST_CASE("File::fetch (cis; double)") {
45+
TEST_CASE("File::fetch (cis)") {
5446
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
5547
test_file1.string(), resolutions.back()))
5648
.chromosomes();
5749

5850
for (const auto& path : {test_file1, test_file2, test_file3}) {
5951
for (const auto& res : resolutions) {
6052
for (const auto& range : {range_small, range_medium, range_large}) {
61-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), range, res))
62-
(Catch::Benchmark::Chronometer meter) {
63-
const File f(path.string(), res);
64-
meter.measure([&f, &range]() {
65-
return count_nnz<double>(f, range, range, balancing::Method::KR());
66-
});
67-
};
53+
run_benchmark<std::uint32_t>(path, res, range, balancing::Method::NONE());
54+
run_benchmark<double>(path, res, range, balancing::Method::KR());
6855
}
6956
}
7057
}

benchmark/interaction_fetching/file_gw_queries.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,26 @@ static const std::filesystem::path test_file3{"test/data/hic/4DNFIZ1ZVXC8.hic9"}
2424
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
2525
100000, 250000, 500000, 1000000, 2500000};
2626

27-
TEST_CASE("File::fetch (gw; uint32)") {
28-
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
29-
test_file1.string(), resolutions.back()))
30-
.chromosomes();
31-
32-
for (const auto& path : {test_file1, test_file2, test_file3}) {
33-
for (const auto& res : resolutions) {
34-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), path.extension(), res))
35-
(Catch::Benchmark::Chronometer meter) {
36-
const File f(path.string(), res);
37-
meter.measure(
38-
[&f]() { return count_nnz<std::uint32_t>(f, 10'000'000, balancing::Method::NONE()); });
39-
};
40-
}
41-
}
27+
template <typename N>
28+
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
29+
const balancing::Method& normalization) {
30+
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp; {}"), path.extension(), resolution,
31+
std::is_integral_v<N> ? "int" : "fp"))
32+
(Catch::Benchmark::Chronometer meter) {
33+
const File f(path.string(), resolution);
34+
meter.measure([&f, &normalization]() { return count_nnz<N>(f, 10'000'000, normalization); });
35+
};
4236
}
4337

44-
TEST_CASE("File::fetch (gw; double)") {
38+
TEST_CASE("File::fetch (gw)") {
4539
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
4640
test_file1.string(), resolutions.back()))
4741
.chromosomes();
4842

4943
for (const auto& path : {test_file1, test_file2, test_file3}) {
5044
for (const auto& res : resolutions) {
51-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), path.extension(), res))
52-
(Catch::Benchmark::Chronometer meter) {
53-
const File f(path.string(), res);
54-
meter.measure(
55-
[&f]() { return count_nnz<std::uint32_t>(f, 10'000'000, balancing::Method::KR()); });
56-
};
45+
run_benchmark<std::uint32_t>(path, res, balancing::Method::NONE());
46+
run_benchmark<double>(path, res, balancing::Method::KR());
5747
}
5848
}
5949
}

benchmark/interaction_fetching/file_trans_queries.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,31 @@ static constexpr std::pair<std::string_view, std::string_view> range_medium{
3535
static constexpr std::pair<std::string_view, std::string_view> range_large{
3636
"chr2L:15,000,000-20,000,000", "chrX:15,000,000-20,000,000"};
3737

38-
TEST_CASE("File::fetch (trans; uint32)") {
39-
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
40-
test_file1.string(), resolutions.back()))
41-
.chromosomes();
42-
43-
for (const auto& path : {test_file1, test_file2, test_file3}) {
44-
for (const auto& res : resolutions) {
45-
for (const auto& query : {range_small, range_medium, range_large}) {
46-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
47-
(Catch::Benchmark::Chronometer meter) {
48-
const File f(path.string(), res);
49-
meter.measure([&f, range1 = query.first, range2 = query.second]() {
50-
return count_nnz<std::uint32_t>(f, range1, range2, balancing::Method::NONE());
51-
});
52-
};
53-
}
54-
}
55-
}
38+
template <typename N>
39+
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
40+
std::string_view range1, std::string_view range2,
41+
const balancing::Method& normalization) {
42+
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}; {}bp; {}"), path.extension(), range1,
43+
range2, resolution, std::is_integral_v<N> ? "int" : "fp"))
44+
(Catch::Benchmark::Chronometer meter) {
45+
const File f(path.string(), resolution);
46+
meter.measure([&f, &range1, &range2, &normalization]() {
47+
return count_nnz<N>(f, range1, range2, normalization);
48+
});
49+
};
5650
}
5751

58-
TEST_CASE("File::fetch (trans; double)") {
52+
TEST_CASE("File::fetch (trans)") {
5953
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
6054
test_file1.string(), resolutions.back()))
6155
.chromosomes();
6256

6357
for (const auto& path : {test_file1, test_file2, test_file3}) {
6458
for (const auto& res : resolutions) {
6559
for (const auto& query : {range_small, range_medium, range_large}) {
66-
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
67-
(Catch::Benchmark::Chronometer meter) {
68-
const File f(path.string(), res);
69-
meter.measure([&f, range1 = query.first, range2 = query.second]() {
70-
return count_nnz<double>(f, range1, range2, balancing::Method::KR());
71-
});
72-
};
60+
run_benchmark<std::uint32_t>(path, res, query.first, query.second,
61+
balancing::Method::NONE());
62+
run_benchmark<double>(path, res, query.first, query.second, balancing::Method::KR());
7363
}
7464
}
7565
}

0 commit comments

Comments
 (0)