Skip to content

Commit

Permalink
Further simplify benchmarks. Add benchmarks for unordered pixel itera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
robomics committed Nov 3, 2024
1 parent 0065c8b commit 19b7364
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 228 deletions.
38 changes: 23 additions & 15 deletions benchmark/interaction_fetching/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@
#include "hictk/chromosome.hpp"
#include "hictk/reference.hpp"

// NOLINTBEGIN(*-avoid-magic-numbers)
struct Params {
std::string_view label{};
bool cis{};

double avg_height{1.0e6};
double avg_width{1.0e6};
double height_std{250.0e3};
double width_std{250.0e3};
std::size_t num_queries{1};
hictk::balancing::Method normalization{hictk::balancing::Method::NONE()};
std::uint64_t seed{123456789};
};
// NOLINTEND(*-avoid-magic-numbers)

[[nodiscard]] inline std::pair<std::string, std::string> generate_query(
std::mt19937_64& rand_eng, const hictk::Chromosome& chrom1, const hictk::Chromosome& chrom2,
double avg_height, double avg_width, double height_std, double width_std) {
Expand Down Expand Up @@ -158,3 +143,26 @@ template <typename N, typename File>
// clang-format on
return i;
}

template <typename N, typename File>
[[nodiscard]] inline std::ptrdiff_t count_nnz_unsorted(
const File& file, std::string_view range1, std::string_view range2,
const hictk::balancing::Method& normalization) {
const auto sel = file.fetch(range1, range2, normalization);

return std::distance(sel.template begin<N>(false), sel.template end<N>());
}

template <typename N, typename File>
[[nodiscard]] inline std::ptrdiff_t count_nnz_unsorted(
const File& file, std::size_t max_num_pixels, const hictk::balancing::Method& normalization) {
const auto sel = file.fetch(normalization);
auto first = sel.template begin<N>(false);
auto last = sel.template end<N>();

std::ptrdiff_t i{};
// clang-format off
while (++first != last && ++i != static_cast<std::ptrdiff_t>(max_num_pixels)); // NOLINT
// clang-format on
return i;
}
40 changes: 15 additions & 25 deletions benchmark/interaction_fetching/cooler_cis_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,28 @@ static constexpr std::string_view range_small{"chr2L:5,000,000-5,100,000"};
static constexpr std::string_view range_medium{"chr2L:6,000,000-7,000,000"};
static constexpr std::string_view range_large{"chr2L:10,000,000-15,000,000"};

TEST_CASE("cooler::File::fetch (cis; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), range, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, &range]() {
return count_nnz<std::uint32_t>(clr, range, range, balancing::Method::NONE());
});
};
}
}
template <typename N>
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
std::string_view range, const balancing::Method& normalization) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp; {}"), range, resolution,
std::is_integral_v<N> ? "int" : "fp"))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), path.string(), resolution));
meter.measure([&clr, &range, &normalization]() {
return count_nnz<N>(clr, range, range, normalization);
});
};
}

TEST_CASE("cooler::File::fetch (cis; double)") {
TEST_CASE("cooler::File::fetch (cis)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), range, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, &range]() {
return count_nnz<double>(clr, range, range, balancing::Method::KR());
});
};
run_benchmark<std::uint32_t>(test_file, res, range, balancing::Method::NONE());
run_benchmark<double>(test_file, res, range, balancing::Method::KR());
}
}
}
Expand Down
36 changes: 14 additions & 22 deletions benchmark/interaction_fetching/cooler_gw_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,26 @@ static const std::filesystem::path test_file{"test/data/integration_tests/4DNFIZ
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
100000, 250000, 500000, 1000000, 2500000};

TEST_CASE("cooler::File::fetch (gw; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}bp"), res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr]() {
return count_nnz<std::uint32_t>(clr, 10'000'000, balancing::Method::NONE());
});
};
}
template <typename N>
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
const balancing::Method& normalization) {
BENCHMARK_ADVANCED(
fmt::format(FMT_STRING("{}bp; {}"), resolution, std::is_integral_v<N> ? "int" : "fp"))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), path.string(), resolution));
meter.measure(
[&clr, &normalization]() { return count_nnz<N>(clr, 10'000'000, normalization); });
};
}

TEST_CASE("cooler::File::fetch (gw; double)") {
TEST_CASE("cooler::File::fetch (gw)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}bp"), res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure(
[&clr]() { return count_nnz<std::uint32_t>(clr, 10'000'000, balancing::Method::KR()); });
};
run_benchmark<std::uint32_t>(test_file, res, balancing::Method::NONE());
run_benchmark<double>(test_file, res, balancing::Method::KR());
}
}
// NOLINTEND(*-avoid-magic-numbers, cert-err58-cpp, readability-function-cognitive-complexity)
42 changes: 17 additions & 25 deletions benchmark/interaction_fetching/cooler_trans_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,30 @@ static constexpr std::pair<std::string_view, std::string_view> range_medium{
static constexpr std::pair<std::string_view, std::string_view> range_large{
"chr2L:15,000,000-20,000,000", "chrX:15,000,000-20,000,000"};

TEST_CASE("cooler::File::fetch (trans; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, range1 = query.first, range2 = query.second]() {
return count_nnz<std::uint32_t>(clr, range1, range2, balancing::Method::NONE());
});
};
}
}
template <typename N>
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
std::string_view range1, std::string_view range2,
const balancing::Method& normalization) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp; {}"), range1, range2, resolution,
std::is_integral_v<N> ? "int" : "fp"))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), path.string(), resolution));
meter.measure([&clr, &range1, &range2, &normalization]() {
return count_nnz<N>(clr, range1, range2, normalization);
});
};
}

TEST_CASE("cooler::File::fetch (trans; double)") {
TEST_CASE("cooler::File::fetch (trans)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, range1 = query.first, range2 = query.second]() {
return count_nnz<double>(clr, range1, range2, balancing::Method::KR());
});
};
run_benchmark<std::uint32_t>(test_file, res, query.first, query.second,
balancing::Method::NONE());
run_benchmark<double>(test_file, res, query.first, query.second, balancing::Method::KR());
}
}
}
Expand Down
39 changes: 13 additions & 26 deletions benchmark/interaction_fetching/file_cis_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,28 @@ static constexpr std::string_view range_small{"chr2L:5,000,000-5,100,000"};
static constexpr std::string_view range_medium{"chr2L:6,000,000-7,000,000"};
static constexpr std::string_view range_large{"chr2L:10,000,000-15,000,000"};

TEST_CASE("File::fetch (cis; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
for (const auto& res : resolutions) {
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), range, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, &range]() {
return count_nnz<std::uint32_t>(f, range, range, balancing::Method::NONE());
});
};
}
}
}
template <typename N>
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
std::string_view range, const balancing::Method& normalization) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp; {}"), path.extension(), range,
resolution, std::is_integral_v<N> ? "int" : "fp"))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), resolution);
meter.measure(
[&f, &range, &normalization]() { return count_nnz<N>(f, range, range, normalization); });
};
}

TEST_CASE("File::fetch (cis; double)") {
TEST_CASE("File::fetch (cis)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
for (const auto& res : resolutions) {
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), range, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, &range]() {
return count_nnz<double>(f, range, range, balancing::Method::KR());
});
};
run_benchmark<std::uint32_t>(path, res, range, balancing::Method::NONE());
run_benchmark<double>(path, res, range, balancing::Method::KR());
}
}
}
Expand Down
34 changes: 12 additions & 22 deletions benchmark/interaction_fetching/file_gw_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,26 @@ static const std::filesystem::path test_file3{"test/data/hic/4DNFIZ1ZVXC8.hic9"}
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
100000, 250000, 500000, 1000000, 2500000};

TEST_CASE("File::fetch (gw; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
for (const auto& res : resolutions) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), path.extension(), res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure(
[&f]() { return count_nnz<std::uint32_t>(f, 10'000'000, balancing::Method::NONE()); });
};
}
}
template <typename N>
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
const balancing::Method& normalization) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp; {}"), path.extension(), resolution,
std::is_integral_v<N> ? "int" : "fp"))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), resolution);
meter.measure([&f, &normalization]() { return count_nnz<N>(f, 10'000'000, normalization); });
};
}

TEST_CASE("File::fetch (gw; double)") {
TEST_CASE("File::fetch (gw)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
for (const auto& res : resolutions) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), path.extension(), res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure(
[&f]() { return count_nnz<std::uint32_t>(f, 10'000'000, balancing::Method::KR()); });
};
run_benchmark<std::uint32_t>(path, res, balancing::Method::NONE());
run_benchmark<double>(path, res, balancing::Method::KR());
}
}
}
Expand Down
42 changes: 16 additions & 26 deletions benchmark/interaction_fetching/file_trans_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,31 @@ static constexpr std::pair<std::string_view, std::string_view> range_medium{
static constexpr std::pair<std::string_view, std::string_view> range_large{
"chr2L:15,000,000-20,000,000", "chrX:15,000,000-20,000,000"};

TEST_CASE("File::fetch (trans; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
for (const auto& res : resolutions) {
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, range1 = query.first, range2 = query.second]() {
return count_nnz<std::uint32_t>(f, range1, range2, balancing::Method::NONE());
});
};
}
}
}
template <typename N>
static void run_benchmark(const std::filesystem::path& path, std::uint32_t resolution,
std::string_view range1, std::string_view range2,
const balancing::Method& normalization) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}; {}bp; {}"), path.extension(), range1,
range2, resolution, std::is_integral_v<N> ? "int" : "fp"))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), resolution);
meter.measure([&f, &range1, &range2, &normalization]() {
return count_nnz<N>(f, range1, range2, normalization);
});
};
}

TEST_CASE("File::fetch (trans; double)") {
TEST_CASE("File::fetch (trans)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
for (const auto& res : resolutions) {
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, range1 = query.first, range2 = query.second]() {
return count_nnz<double>(f, range1, range2, balancing::Method::KR());
});
};
run_benchmark<std::uint32_t>(path, res, query.first, query.second,
balancing::Method::NONE());
run_benchmark<double>(path, res, query.first, query.second, balancing::Method::KR());
}
}
}
Expand Down
Loading

0 comments on commit 19b7364

Please sign in to comment.