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
3 changes: 2 additions & 1 deletion .github/workflows/clang-tidy-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
split_workflow: true
config_file: .clang-tidy
cmake_command: >
bash -x -c '
source /opt/root/bin/thisroot.sh &&
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang"
Expand All @@ -61,7 +62,7 @@ jobs:
-DRAMTOOLS_BUILD_TOOLS=ON
-DRAMTOOLS_BUILD_BENCHMARKS=ON &&
cd build &&
cmake --build . --target googletest --parallel $(nproc --all)
cmake --build . --target googletest --parallel $(nproc --all) || true'

- name: Upload artifacts
if: always()
Expand Down
17 changes: 10 additions & 7 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
include(GoogleBenchmark)

add_library(sam_generator STATIC
add_library(sam_generator STATIC
generate_sam_benchmark.cxx
)

Expand All @@ -12,19 +12,22 @@ target_include_directories(sam_generator PUBLIC
target_link_libraries(sam_generator PRIVATE benchmark::benchmark)
add_dependencies(sam_generator benchmark::benchmark)

ROOT_EXECUTABLE(generate_sam_benchmark
generate_sam_benchmark.cxx
ROOT_EXECUTABLE(sam_to_ram_benchmark
sam_to_ram_benchmark.cxx
LIBRARIES
benchmark::benchmark
ramcore
sam_generator
)

install(TARGETS generate_sam_benchmark
install(TARGETS sam_to_ram_benchmark
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

add_custom_target(benchmark
COMMAND generate_sam_benchmark
DEPENDS generate_sam_benchmark
COMMAND sam_to_ram_benchmark
DEPENDS sam_to_ram_benchmark
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running SAM generation benchmarks"
COMMENT "Running SAM to RAM conversion benchmark"
)

24 changes: 0 additions & 24 deletions benchmark/generate_sam_benchmark.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,3 @@ static void BM_GenerateSAM(benchmark::State& state) {
state.counters["bytes_per_second"] = benchmark::Counter(
num_reads * 200, benchmark::Counter::kIsRate);
}

int main(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--generate" && i + 1 < argc) {
std::string filename = argv[i + 1];
int num_reads = (i + 2 < argc) ? std::stoi(argv[i + 2]) : BASE_SAM_READS;
GenerateSAMFile(filename, num_reads);
std::cout << "Generated SAM file: " << filename << " with " << num_reads << " reads" << std::endl;
return 0;
}
}

std::cout << "Benchmarking SAM generation with a range of reads..." << std::endl;

::benchmark::RegisterBenchmark("BM_GenerateSAM", BM_GenerateSAM)
->RangeMultiplier(10)
->Range(100, 100000)
->Unit(benchmark::kMicrosecond);

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
return 0;
}

70 changes: 70 additions & 0 deletions benchmark/sam_to_ram_benchmark.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <benchmark/benchmark.h>
#include "generate_sam_benchmark.h"
#include "ramcore/SamToTTree.h"
#include "ramcore/SamToNTuple.h"
#include <filesystem>
#include <iostream>
#include <cstdio>
#include <cstring>

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

std::string sam_file = "benchmark_test.sam";
std::string ttree_file = "benchmark_ttree.root";
std::string rntuple_file = "benchmark_rntuple.root";

GenerateSAMFile(sam_file, num_reads);

for (auto _ : state) {

FILE *original_stdout = stdout;
stdout = fopen("/dev/null", "w");

samtoram(sam_file.c_str(), ttree_file.c_str(), true, true, true, 1, 0);

samtoramntuple(sam_file.c_str(), rntuple_file.c_str(), true, true, true, 505, 0);

fclose(stdout);
stdout = original_stdout;

if (std::filesystem::exists(ttree_file)) {
auto ttree_size = std::filesystem::file_size(ttree_file);
state.counters["ttree_size_mb"] = ttree_size / (1024.0 * 1024.0);
}

if (std::filesystem::exists(rntuple_file)) {
auto rntuple_size = std::filesystem::file_size(rntuple_file);
state.counters["rntuple_size_mb"] = rntuple_size / (1024.0 * 1024.0);
}

if (state.counters["ttree_size_mb"] > 0 && state.counters["rntuple_size_mb"] > 0) {
state.counters["compression_ratio"] = state.counters["ttree_size_mb"] / state.counters["rntuple_size_mb"];
}
}

std::remove(sam_file.c_str());
std::remove(ttree_file.c_str());
std::remove(rntuple_file.c_str());

state.counters["reads"] = num_reads;
state.counters["reads_per_second"] = benchmark::Counter(num_reads, benchmark::Counter::kIsRate);
}

int main(int argc, char **argv)
{
std::cout << "SAM to RAM Conversion Benchmark" << std::endl;
std::cout << "Comparing TTree vs RNTuple performance and file sizes" << std::endl;
std::cout << std::endl;

::benchmark::RegisterBenchmark("BM_SamToRamComparison", BM_SamToRamComparison)
->Args({1000})
->Args({10000})
->Args({100000})
->Unit(benchmark::kMillisecond);

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
return 0;
}