diff --git a/benchmark/interaction_fetching/common.hpp b/benchmark/interaction_fetching/common.hpp index e47ef221..7086ab0c 100644 --- a/benchmark/interaction_fetching/common.hpp +++ b/benchmark/interaction_fetching/common.hpp @@ -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 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) { @@ -158,3 +143,26 @@ template // clang-format on return i; } + +template +[[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(false), sel.template end()); +} + +template +[[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(false); + auto last = sel.template end(); + + std::ptrdiff_t i{}; + // clang-format off + while (++first != last && ++i != static_cast(max_num_pixels)); // NOLINT + // clang-format on + return i; +} diff --git a/benchmark/interaction_fetching/cooler_cis_queries.cpp b/benchmark/interaction_fetching/cooler_cis_queries.cpp index 4f13c7a0..1e3ea4fa 100644 --- a/benchmark/interaction_fetching/cooler_cis_queries.cpp +++ b/benchmark/interaction_fetching/cooler_cis_queries.cpp @@ -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(clr, range, range, balancing::Method::NONE()); - }); - }; - } - } +template +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 ? "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(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(clr, range, range, balancing::Method::KR()); - }); - }; + run_benchmark(test_file, res, range, balancing::Method::NONE()); + run_benchmark(test_file, res, range, balancing::Method::KR()); } } } diff --git a/benchmark/interaction_fetching/cooler_gw_queries.cpp b/benchmark/interaction_fetching/cooler_gw_queries.cpp index 63841639..07e6806b 100644 --- a/benchmark/interaction_fetching/cooler_gw_queries.cpp +++ b/benchmark/interaction_fetching/cooler_gw_queries.cpp @@ -21,34 +21,26 @@ static const std::filesystem::path test_file{"test/data/integration_tests/4DNFIZ static const std::vector 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(clr, 10'000'000, balancing::Method::NONE()); - }); - }; - } +template +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 ? "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(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(clr, 10'000'000, balancing::Method::KR()); }); - }; + run_benchmark(test_file, res, balancing::Method::NONE()); + run_benchmark(test_file, res, balancing::Method::KR()); } } // NOLINTEND(*-avoid-magic-numbers, cert-err58-cpp, readability-function-cognitive-complexity) diff --git a/benchmark/interaction_fetching/cooler_trans_queries.cpp b/benchmark/interaction_fetching/cooler_trans_queries.cpp index 7f75ac19..d6fd1e50 100644 --- a/benchmark/interaction_fetching/cooler_trans_queries.cpp +++ b/benchmark/interaction_fetching/cooler_trans_queries.cpp @@ -32,38 +32,30 @@ static constexpr std::pair range_medium{ static constexpr std::pair 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(clr, range1, range2, balancing::Method::NONE()); - }); - }; - } - } +template +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 ? "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(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(clr, range1, range2, balancing::Method::KR()); - }); - }; + run_benchmark(test_file, res, query.first, query.second, + balancing::Method::NONE()); + run_benchmark(test_file, res, query.first, query.second, balancing::Method::KR()); } } } diff --git a/benchmark/interaction_fetching/file_cis_queries.cpp b/benchmark/interaction_fetching/file_cis_queries.cpp index 595bbcd6..a883e579 100644 --- a/benchmark/interaction_fetching/file_cis_queries.cpp +++ b/benchmark/interaction_fetching/file_cis_queries.cpp @@ -30,27 +30,19 @@ 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(f, range, range, balancing::Method::NONE()); - }); - }; - } - } - } +template +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 ? "int" : "fp")) + (Catch::Benchmark::Chronometer meter) { + const File f(path.string(), resolution); + meter.measure( + [&f, &range, &normalization]() { return count_nnz(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(); @@ -58,13 +50,8 @@ TEST_CASE("File::fetch (cis; double)") { 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(f, range, range, balancing::Method::KR()); - }); - }; + run_benchmark(path, res, range, balancing::Method::NONE()); + run_benchmark(path, res, range, balancing::Method::KR()); } } } diff --git a/benchmark/interaction_fetching/file_gw_queries.cpp b/benchmark/interaction_fetching/file_gw_queries.cpp index 41dd932f..9bed8d07 100644 --- a/benchmark/interaction_fetching/file_gw_queries.cpp +++ b/benchmark/interaction_fetching/file_gw_queries.cpp @@ -24,36 +24,26 @@ static const std::filesystem::path test_file3{"test/data/hic/4DNFIZ1ZVXC8.hic9"} static const std::vector 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(f, 10'000'000, balancing::Method::NONE()); }); - }; - } - } +template +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 ? "int" : "fp")) + (Catch::Benchmark::Chronometer meter) { + const File f(path.string(), resolution); + meter.measure([&f, &normalization]() { return count_nnz(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(f, 10'000'000, balancing::Method::KR()); }); - }; + run_benchmark(path, res, balancing::Method::NONE()); + run_benchmark(path, res, balancing::Method::KR()); } } } diff --git a/benchmark/interaction_fetching/file_trans_queries.cpp b/benchmark/interaction_fetching/file_trans_queries.cpp index def45a94..01991e63 100644 --- a/benchmark/interaction_fetching/file_trans_queries.cpp +++ b/benchmark/interaction_fetching/file_trans_queries.cpp @@ -35,27 +35,21 @@ static constexpr std::pair range_medium{ static constexpr std::pair 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(f, range1, range2, balancing::Method::NONE()); - }); - }; - } - } - } +template +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 ? "int" : "fp")) + (Catch::Benchmark::Chronometer meter) { + const File f(path.string(), resolution); + meter.measure([&f, &range1, &range2, &normalization]() { + return count_nnz(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(); @@ -63,13 +57,9 @@ TEST_CASE("File::fetch (trans; double)") { 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(f, range1, range2, balancing::Method::KR()); - }); - }; + run_benchmark(path, res, query.first, query.second, + balancing::Method::NONE()); + run_benchmark(path, res, query.first, query.second, balancing::Method::KR()); } } } diff --git a/benchmark/interaction_fetching/hic_cis_queries.cpp b/benchmark/interaction_fetching/hic_cis_queries.cpp index 4eebb1d5..b385ef44 100644 --- a/benchmark/interaction_fetching/hic_cis_queries.cpp +++ b/benchmark/interaction_fetching/hic_cis_queries.cpp @@ -28,37 +28,34 @@ 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("hic::File::fetch (cis; uint32)") { - const auto chroms = hic::File(test_file1.string(), resolutions.back()).chromosomes(); - - for (const auto& path : {test_file1, test_file2}) { - 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 hic::File hf(path.string(), res); - meter.measure([&hf, &range]() { - return count_nnz(hf, range, range, balancing::Method::NONE()); - }); - }; +template +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, + sorted ? "sorted" : "unsorted", + std::is_integral_v ? "int" : "fp")) + (Catch::Benchmark::Chronometer meter) { + const hic::File hf(path.string(), resolution); + meter.measure([&hf, &range, &normalization]() { + if constexpr (sorted) { + return count_nnz(hf, range, range, normalization); + } else { + return count_nnz_unsorted(hf, range, range, normalization); } - } - } + }); + }; } -TEST_CASE("hic::File::fetch (cis; double)") { +TEST_CASE("hic::File::fetch (cis)") { const auto chroms = hic::File(test_file1.string(), resolutions.back()).chromosomes(); for (const auto& path : {test_file1, test_file2}) { 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 hic::File hf(path.string(), res); - meter.measure([&hf, &range]() { - return count_nnz(hf, range, range, balancing::Method::KR()); - }); - }; + run_benchmark(path, res, range, balancing::Method::NONE()); + run_benchmark(path, res, range, balancing::Method::NONE()); + run_benchmark(path, res, range, balancing::Method::KR()); + run_benchmark(path, res, range, balancing::Method::KR()); } } } diff --git a/benchmark/interaction_fetching/hic_gw_queries.cpp b/benchmark/interaction_fetching/hic_gw_queries.cpp index 6ead5f4c..e1a98a3d 100644 --- a/benchmark/interaction_fetching/hic_gw_queries.cpp +++ b/benchmark/interaction_fetching/hic_gw_queries.cpp @@ -22,33 +22,33 @@ static const std::filesystem::path test_file2{"test/data/hic/4DNFIZ1ZVXC8.hic9"} static const std::vector resolutions{1000, 5000, 10000, 25000, 50000, 100000, 250000, 500000, 1000000, 2500000}; -TEST_CASE("hic::File::fetch (gw; uint32)") { - const auto chroms = hic::File(test_file1.string(), resolutions.back()).chromosomes(); - - for (const auto& path : {test_file1, test_file2}) { - for (const auto& res : resolutions) { - BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}bp"), res)) - (Catch::Benchmark::Chronometer meter) { - const hic::File hf(path.string(), res); - meter.measure([&hf]() { - return count_nnz(hf, 10'000'000, balancing::Method::NONE()); - }); - }; - } - } +template +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, + sorted ? "sorted" : "unsorted", + std::is_integral_v ? "int" : "fp")) + (Catch::Benchmark::Chronometer meter) { + const hic::File hf(path.string(), resolution); + meter.measure([&hf, &normalization]() { + if constexpr (sorted) { + return count_nnz(hf, 10'000'000, normalization); + } else { + return count_nnz_unsorted(hf, 10'000'000, normalization); + } + }); + }; } -TEST_CASE("hic::File::fetch (gw; double)") { +TEST_CASE("hic::File::fetch (gw)") { const auto chroms = hic::File(test_file1.string(), resolutions.back()).chromosomes(); for (const auto& path : {test_file1, test_file2}) { for (const auto& res : resolutions) { - BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}bp"), res)) - (Catch::Benchmark::Chronometer meter) { - const hic::File hf(path.string(), res); - meter.measure( - [&hf]() { return count_nnz(hf, 10'000'000, balancing::Method::KR()); }); - }; + run_benchmark(path, res, balancing::Method::NONE()); + run_benchmark(path, res, balancing::Method::NONE()); + run_benchmark(path, res, balancing::Method::KR()); + run_benchmark(path, res, balancing::Method::KR()); } } } diff --git a/benchmark/interaction_fetching/hic_trans_queries.cpp b/benchmark/interaction_fetching/hic_trans_queries.cpp index 49f70466..116382eb 100644 --- a/benchmark/interaction_fetching/hic_trans_queries.cpp +++ b/benchmark/interaction_fetching/hic_trans_queries.cpp @@ -33,37 +33,37 @@ static constexpr std::pair range_medium{ static constexpr std::pair range_large{ "chr2L:15,000,000-20,000,000", "chrX:15,000,000-20,000,000"}; -TEST_CASE("hic::File::fetch (trans; uint32)") { - const auto chroms = hic::File(test_file1.string(), resolutions.back()).chromosomes(); - - for (const auto& path : {test_file1, test_file2}) { - 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 hic::File hf(path.string(), res); - meter.measure([&hf, range1 = query.first, range2 = query.second]() { - return count_nnz(hf, range1, range2, balancing::Method::NONE()); - }); - }; +template +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, + sorted ? "sorted" : "unsorted", + std::is_integral_v ? "int" : "fp")) + (Catch::Benchmark::Chronometer meter) { + const hic::File hf(path.string(), resolution); + meter.measure([&hf, &range1, &range2, &normalization]() { + if constexpr (sorted) { + return count_nnz(hf, range1, range2, normalization); + } else { + return count_nnz_unsorted(hf, range1, range2, normalization); } - } - } + }); + }; } -TEST_CASE("hic::File::fetch (trans; double)") { +TEST_CASE("hic::File::fetch (trans)") { const auto chroms = hic::File(test_file1.string(), resolutions.back()).chromosomes(); for (const auto& path : {test_file1, test_file2}) { 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 hic::File hf(path.string(), res); - meter.measure([&hf, range1 = query.first, range2 = query.second]() { - return count_nnz(hf, range1, range2, balancing::Method::KR()); - }); - }; + run_benchmark(path, res, query.first, query.second, + balancing::Method::NONE()); + run_benchmark(path, res, query.first, query.second, + balancing::Method::NONE()); + run_benchmark(path, res, query.first, query.second, balancing::Method::KR()); + run_benchmark(path, res, query.first, query.second, balancing::Method::KR()); } } }