Skip to content

Commit 0a8d0ed

Browse files
clang-tidy changes
Signed-off-by: AdityaPandeyCN <[email protected]>
1 parent 80131e5 commit 0a8d0ed

File tree

1 file changed

+66
-64
lines changed

1 file changed

+66
-64
lines changed

benchmark/sam_to_ram_benchmark.cxx

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,74 @@
1010

1111
static void BM_SamToRamComparison(benchmark::State &state)
1212
{
13-
int num_reads = state.range(0);
14-
std::string sam_file = "test_data.sam";
15-
std::string ttree_file = "output_ttree.root";
16-
std::string rntuple_file = "output_rntuple.root";
17-
18-
GenerateSAMFile(sam_file, num_reads);
19-
20-
for (auto _ : state) {
21-
FILE *original_stdout = stdout;
22-
stdout = fopen("/dev/null", "w");
23-
24-
auto ttree_start = std::chrono::high_resolution_clock::now();
25-
samtoram(sam_file.c_str(), ttree_file.c_str(), true, true, true, 1, 0);
26-
auto ttree_end = std::chrono::high_resolution_clock::now();
27-
28-
auto rntuple_start = std::chrono::high_resolution_clock::now();
29-
samtoramntuple(sam_file.c_str(), rntuple_file.c_str(), true, true, true, 505, 0);
30-
auto rntuple_end = std::chrono::high_resolution_clock::now();
31-
32-
fclose(stdout);
33-
stdout = original_stdout;
34-
35-
auto ttree_time = std::chrono::duration_cast<std::chrono::milliseconds>(ttree_end - ttree_start).count();
36-
auto rntuple_time = std::chrono::duration_cast<std::chrono::milliseconds>(rntuple_end - rntuple_start).count();
37-
38-
double ttree_size_mb = 0, rntuple_size_mb = 0;
39-
if (std::filesystem::exists(ttree_file)) {
40-
auto ttree_size = std::filesystem::file_size(ttree_file);
41-
ttree_size_mb = ttree_size / (1024.0 * 1024.0);
42-
}
43-
44-
if (std::filesystem::exists(rntuple_file)) {
45-
auto rntuple_size = std::filesystem::file_size(rntuple_file);
46-
rntuple_size_mb = rntuple_size / (1024.0 * 1024.0);
47-
}
48-
49-
double compression_ratio = (rntuple_size_mb > 0) ? ttree_size_mb / rntuple_size_mb : 0;
50-
51-
std::cout << "\n=== Results for " << num_reads << " reads ===" << std::endl;
52-
std::cout << "TTree conversion time: " << std::setw(8) << ttree_time << " ms" << std::endl;
53-
std::cout << "RNTuple conversion time: " << std::setw(8) << rntuple_time << " ms" << std::endl;
54-
std::cout << "TTree file size: " << std::setw(8) << std::fixed << std::setprecision(2) << ttree_size_mb << " MB" << std::endl;
55-
std::cout << "RNTuple file size: " << std::setw(8) << std::fixed << std::setprecision(2) << rntuple_size_mb << " MB" << std::endl;
56-
std::cout << "Compression ratio: " << std::setw(8) << std::fixed << std::setprecision(2) << compression_ratio << "x" << std::endl;
57-
std::cout << "========================================" << std::endl;
58-
59-
std::remove(ttree_file.c_str());
60-
std::remove(rntuple_file.c_str());
61-
}
62-
63-
std::remove(sam_file.c_str());
13+
int num_reads = state.range(0);
14+
std::string sam_file = "test_data.sam";
15+
std::string ttree_file = "output_ttree.root";
16+
std::string rntuple_file = "output_rntuple.root";
17+
18+
GenerateSAMFile(sam_file, num_reads);
19+
20+
for (auto _ : state) {
21+
FILE *original_stdout = stdout;
22+
stdout = fopen("/dev/null", "w");
23+
24+
auto ttree_start = std::chrono::high_resolution_clock::now();
25+
samtoram(sam_file.c_str(), ttree_file.c_str(), true, true, true, 1, 0);
26+
auto ttree_end = std::chrono::high_resolution_clock::now();
27+
28+
auto rntuple_start = std::chrono::high_resolution_clock::now();
29+
samtoramntuple(sam_file.c_str(), rntuple_file.c_str(), true, true, true, 505, 0);
30+
auto rntuple_end = std::chrono::high_resolution_clock::now();
31+
32+
fclose(stdout);
33+
stdout = original_stdout;
34+
35+
auto ttree_time = std::chrono::duration_cast<std::chrono::milliseconds>(ttree_end - ttree_start).count();
36+
auto rntuple_time = std::chrono::duration_cast<std::chrono::milliseconds>(rntuple_end - rntuple_start).count();
37+
38+
double ttree_size_mb = 0, rntuple_size_mb = 0;
39+
if (std::filesystem::exists(ttree_file)) {
40+
auto ttree_size = std::filesystem::file_size(ttree_file);
41+
ttree_size_mb = ttree_size / (1024.0 * 1024.0);
42+
}
43+
44+
if (std::filesystem::exists(rntuple_file)) {
45+
auto rntuple_size = std::filesystem::file_size(rntuple_file);
46+
rntuple_size_mb = rntuple_size / (1024.0 * 1024.0);
47+
}
48+
49+
double compression_ratio = (rntuple_size_mb > 0) ? ttree_size_mb / rntuple_size_mb : 0;
50+
51+
std::cout << "\n=== Results for " << num_reads << " reads ===" << std::endl;
52+
std::cout << "TTree conversion time: " << std::setw(8) << ttree_time << " ms" << std::endl;
53+
std::cout << "RNTuple conversion time: " << std::setw(8) << rntuple_time << " ms" << std::endl;
54+
std::cout << "TTree file size: " << std::setw(8) << std::fixed << std::setprecision(2) << ttree_size_mb
55+
<< " MB" << std::endl;
56+
std::cout << "RNTuple file size: " << std::setw(8) << std::fixed << std::setprecision(2) << rntuple_size_mb
57+
<< " MB" << std::endl;
58+
std::cout << "Compression ratio: " << std::setw(8) << std::fixed << std::setprecision(2)
59+
<< compression_ratio << "x" << std::endl;
60+
std::cout << "========================================" << std::endl;
61+
62+
std::remove(ttree_file.c_str());
63+
std::remove(rntuple_file.c_str());
64+
}
65+
66+
std::remove(sam_file.c_str());
6467
}
6568

6669
int main(int argc, char **argv)
6770
{
68-
std::cout << "SAM to ROOT Conversion Benchmark" << std::endl;
69-
std::cout << "=================================" << std::endl;
70-
71-
::benchmark::RegisterBenchmark("SAM_Conversion", BM_SamToRamComparison)
72-
->Args({10000})
73-
->Args({100000})
74-
->Args({10000000})
75-
->Unit(benchmark::kMillisecond);
76-
77-
::benchmark::Initialize(&argc, argv);
78-
::benchmark::RunSpecifiedBenchmarks();
79-
return 0;
80-
}
71+
std::cout << "SAM to ROOT Conversion Benchmark" << std::endl;
72+
std::cout << "=================================" << std::endl;
73+
74+
::benchmark::RegisterBenchmark("SAM_Conversion", BM_SamToRamComparison)
75+
->Args({10000})
76+
->Args({100000})
77+
->Args({10000000})
78+
->Unit(benchmark::kMillisecond);
8179

80+
::benchmark::Initialize(&argc, argv);
81+
::benchmark::RunSpecifiedBenchmarks();
82+
return 0;
83+
}

0 commit comments

Comments
 (0)