Skip to content

Commit c3278fc

Browse files
SAM to RAM conversion benchmark (#6)
1 parent 73e0569 commit c3278fc

File tree

4 files changed

+82
-32
lines changed

4 files changed

+82
-32
lines changed

.github/workflows/clang-tidy-review.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
split_workflow: true
5151
config_file: .clang-tidy
5252
cmake_command: >
53+
bash -x -c '
5354
source /opt/root/bin/thisroot.sh &&
5455
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
5556
-DCMAKE_C_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang"
@@ -61,7 +62,7 @@ jobs:
6162
-DRAMTOOLS_BUILD_TOOLS=ON
6263
-DRAMTOOLS_BUILD_BENCHMARKS=ON &&
6364
cd build &&
64-
cmake --build . --target googletest --parallel $(nproc --all)
65+
cmake --build . --target googletest --parallel $(nproc --all) || true'
6566
6667
- name: Upload artifacts
6768
if: always()

benchmark/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
22
include(GoogleBenchmark)
33

4-
add_library(sam_generator STATIC
4+
add_library(sam_generator STATIC
55
generate_sam_benchmark.cxx
66
)
77

@@ -12,19 +12,22 @@ target_include_directories(sam_generator PUBLIC
1212
target_link_libraries(sam_generator PRIVATE benchmark::benchmark)
1313
add_dependencies(sam_generator benchmark::benchmark)
1414

15-
ROOT_EXECUTABLE(generate_sam_benchmark
16-
generate_sam_benchmark.cxx
15+
ROOT_EXECUTABLE(sam_to_ram_benchmark
16+
sam_to_ram_benchmark.cxx
1717
LIBRARIES
1818
benchmark::benchmark
19+
ramcore
20+
sam_generator
1921
)
2022

21-
install(TARGETS generate_sam_benchmark
23+
install(TARGETS sam_to_ram_benchmark
2224
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2325
)
2426

2527
add_custom_target(benchmark
26-
COMMAND generate_sam_benchmark
27-
DEPENDS generate_sam_benchmark
28+
COMMAND sam_to_ram_benchmark
29+
DEPENDS sam_to_ram_benchmark
2830
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
29-
COMMENT "Running SAM generation benchmarks"
31+
COMMENT "Running SAM to RAM conversion benchmark"
3032
)
33+

benchmark/generate_sam_benchmark.cxx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,3 @@ static void BM_GenerateSAM(benchmark::State& state) {
9292
state.counters["bytes_per_second"] = benchmark::Counter(
9393
num_reads * 200, benchmark::Counter::kIsRate);
9494
}
95-
96-
int main(int argc, char** argv) {
97-
for (int i = 1; i < argc; ++i) {
98-
if (std::string(argv[i]) == "--generate" && i + 1 < argc) {
99-
std::string filename = argv[i + 1];
100-
int num_reads = (i + 2 < argc) ? std::stoi(argv[i + 2]) : BASE_SAM_READS;
101-
GenerateSAMFile(filename, num_reads);
102-
std::cout << "Generated SAM file: " << filename << " with " << num_reads << " reads" << std::endl;
103-
return 0;
104-
}
105-
}
106-
107-
std::cout << "Benchmarking SAM generation with a range of reads..." << std::endl;
108-
109-
::benchmark::RegisterBenchmark("BM_GenerateSAM", BM_GenerateSAM)
110-
->RangeMultiplier(10)
111-
->Range(100, 100000)
112-
->Unit(benchmark::kMicrosecond);
113-
114-
::benchmark::Initialize(&argc, argv);
115-
::benchmark::RunSpecifiedBenchmarks();
116-
return 0;
117-
}
118-

benchmark/sam_to_ram_benchmark.cxx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <benchmark/benchmark.h>
2+
#include "generate_sam_benchmark.h"
3+
#include "ramcore/SamToTTree.h"
4+
#include "ramcore/SamToNTuple.h"
5+
#include <filesystem>
6+
#include <iostream>
7+
#include <cstdio>
8+
#include <cstring>
9+
10+
static void BM_SamToRamComparison(benchmark::State &state)
11+
{
12+
int num_reads = state.range(0);
13+
14+
std::string sam_file = "benchmark_test.sam";
15+
std::string ttree_file = "benchmark_ttree.root";
16+
std::string rntuple_file = "benchmark_rntuple.root";
17+
18+
GenerateSAMFile(sam_file, num_reads);
19+
20+
for (auto _ : state) {
21+
22+
FILE *original_stdout = stdout;
23+
stdout = fopen("/dev/null", "w");
24+
25+
samtoram(sam_file.c_str(), ttree_file.c_str(), true, true, true, 1, 0);
26+
27+
samtoramntuple(sam_file.c_str(), rntuple_file.c_str(), true, true, true, 505, 0);
28+
29+
fclose(stdout);
30+
stdout = original_stdout;
31+
32+
if (std::filesystem::exists(ttree_file)) {
33+
auto ttree_size = std::filesystem::file_size(ttree_file);
34+
state.counters["ttree_size_mb"] = ttree_size / (1024.0 * 1024.0);
35+
}
36+
37+
if (std::filesystem::exists(rntuple_file)) {
38+
auto rntuple_size = std::filesystem::file_size(rntuple_file);
39+
state.counters["rntuple_size_mb"] = rntuple_size / (1024.0 * 1024.0);
40+
}
41+
42+
if (state.counters["ttree_size_mb"] > 0 && state.counters["rntuple_size_mb"] > 0) {
43+
state.counters["compression_ratio"] = state.counters["ttree_size_mb"] / state.counters["rntuple_size_mb"];
44+
}
45+
}
46+
47+
std::remove(sam_file.c_str());
48+
std::remove(ttree_file.c_str());
49+
std::remove(rntuple_file.c_str());
50+
51+
state.counters["reads"] = num_reads;
52+
state.counters["reads_per_second"] = benchmark::Counter(num_reads, benchmark::Counter::kIsRate);
53+
}
54+
55+
int main(int argc, char **argv)
56+
{
57+
std::cout << "SAM to RAM Conversion Benchmark" << std::endl;
58+
std::cout << "Comparing TTree vs RNTuple performance and file sizes" << std::endl;
59+
std::cout << std::endl;
60+
61+
::benchmark::RegisterBenchmark("BM_SamToRamComparison", BM_SamToRamComparison)
62+
->Args({1000})
63+
->Args({10000})
64+
->Args({100000})
65+
->Unit(benchmark::kMillisecond);
66+
67+
::benchmark::Initialize(&argc, argv);
68+
::benchmark::RunSpecifiedBenchmarks();
69+
return 0;
70+
}

0 commit comments

Comments
 (0)