Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ target_include_directories(sam_generator PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(sam_generator PRIVATE benchmark::benchmark)
add_dependencies(sam_generator benchmark::benchmark)
target_link_libraries(sam_generator PRIVATE
benchmark::benchmark
)

add_library(ramtools_views STATIC
${CMAKE_SOURCE_DIR}/tools/ramview.cxx
${CMAKE_SOURCE_DIR}/tools/ramntupleview.cxx
)

target_link_libraries(ramtools_views PRIVATE
ramcore
ROOT::TreePlayer
)

ROOT_EXECUTABLE(sam_to_ram_benchmark
sam_to_ram_benchmark.cxx
Expand All @@ -28,14 +39,30 @@ ROOT_EXECUTABLE(conversion_time_benchmark
sam_generator
)

install(TARGETS sam_to_ram_benchmark conversion_time_benchmark
ROOT_EXECUTABLE(region_query_benchmark
region_query_benchmark.cxx
LIBRARIES
benchmark::benchmark
ramcore
sam_generator
ramtools_views
)

install(TARGETS sam_to_ram_benchmark conversion_time_benchmark region_query_benchmark
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

add_custom_target(benchmark
COMMAND ${CMAKE_COMMAND} -E echo "=== SAM to RAM Benchmark ==="
COMMAND sam_to_ram_benchmark
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "=== Conversion Time Benchmark ==="
COMMAND conversion_time_benchmark
DEPENDS sam_to_ram_benchmark conversion_time_benchmark
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "=== Region Query Benchmark ==="
COMMAND region_query_benchmark
DEPENDS sam_to_ram_benchmark conversion_time_benchmark region_query_benchmark
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running all RAM tools benchmarks"
)

7 changes: 7 additions & 0 deletions benchmark/benchmark_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#ifdef _WIN32
#define NULL_DEVICE "NUL"
#else
#define NULL_DEVICE "/dev/null"
#endif
86 changes: 86 additions & 0 deletions benchmark/region_query_benchmark.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <benchmark/benchmark.h>
#include "generate_sam_benchmark.h"
#include "benchmark_utils.h"
#include "ramcore/SamToTTree.h"
#include "ramcore/SamToNTuple.h"
#include <string>
#include <cstdio>

void ramview(const char *file, const char *query, bool cache = true, bool perfstats = false,
const char *perfstatsfilename = "perf.root");
void ramntupleview(const char *file, const char *query, bool cache = true, bool perfstats = false,
const char *perfstatsfilename = "perf.root");

class RegionQueryFixture : public benchmark::Fixture {
public:
void SetUp(const benchmark::State &state) override
{
num_reads_ = static_cast<int>(state.range(0));
sam_file_ = "region_query_test_" + std::to_string(num_reads_) + ".sam";

GenerateSAMFile(sam_file_, num_reads_);
}

void TearDown(const benchmark::State &) override { std::remove(sam_file_.c_str()); }

protected:
int num_reads_;
std::string sam_file_;
static constexpr const char *region_ = "chr1:1-100000000";

void suppress_output() { freopen(NULL_DEVICE, "w", stdout); }

void restore_output() { freopen("/dev/tty", "w", stdout); }
};

BENCHMARK_DEFINE_F(RegionQueryFixture, TTree)(benchmark::State &state)
{
std::string root_file = "ttree_" + std::to_string(num_reads_) + ".root";

suppress_output();
samtoram(sam_file_.c_str(), root_file.c_str(), true, true, true, 1, 0);
restore_output();

for (auto _ : state) {
suppress_output();
ramview(root_file.c_str(), region_, true, false, "perf.root");
restore_output();
}

std::remove(root_file.c_str());

state.counters["reads_per_sec"] = benchmark::Counter(num_reads_, benchmark::Counter::kIsRate);
}

BENCHMARK_DEFINE_F(RegionQueryFixture, RNTuple)(benchmark::State &state)
{
std::string root_file = "rntuple_" + std::to_string(num_reads_) + ".root";

suppress_output();
samtoramntuple(sam_file_.c_str(), root_file.c_str(), true, true, true, 505, 0);
restore_output();

for (auto _ : state) {
suppress_output();
ramntupleview(root_file.c_str(), region_, true, false, "perf.root");
restore_output();
}

std::remove(root_file.c_str());

state.counters["reads_per_sec"] = benchmark::Counter(num_reads_, benchmark::Counter::kIsRate);
}

BENCHMARK_REGISTER_F(RegionQueryFixture, TTree)
->Args({1000})
->Args({10000})
->Args({100000})
->Unit(benchmark::kMillisecond);

BENCHMARK_REGISTER_F(RegionQueryFixture, RNTuple)
->Args({1000})
->Args({10000})
->Args({100000})
->Unit(benchmark::kMillisecond);

BENCHMARK_MAIN();
7 changes: 1 addition & 6 deletions benchmark/sam_to_ram_benchmark.cxx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#include <benchmark/benchmark.h>
#include "generate_sam_benchmark.h"
#include "benchmark_utils.h"
#include "ramcore/SamToTTree.h"
#include "ramcore/SamToNTuple.h"
#include <filesystem>
#include <iostream>
#include <cstdio>
#include <cstring>

#ifdef _WIN32
#define NULL_DEVICE "NUL"
#else
#define NULL_DEVICE "/dev/null"
#endif

static void BM_SamToRamComparison(benchmark::State &state)
{
int num_reads = state.range(0);
Expand Down