Skip to content
Open
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
60 changes: 60 additions & 0 deletions benchmark/conversion_time_benchmark.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
#include <filesystem>
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header vector is not used directly [misc-include-cleaner]

Suggested change
#include <string>
#include <string>


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

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static std::vector<std::string> input_files;

static void BM_SamToTTree(benchmark::State &state)
{
int num_reads = state.range(0);
Expand Down Expand Up @@ -72,8 +77,63 @@ static void BM_SamToRNTuple(benchmark::State &state)
state.counters["reads_per_second"] = benchmark::Counter(num_reads, benchmark::Counter::kIsRate);
}

static void BM_SamToRNTupleRealData(benchmark::State &state)
{
auto file_index = static_cast<std::size_t>(state.range(0));
std::string sam_file = input_files[file_index];
std::string rntuple_file = sam_file + ".rntuple.root";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

   std::string rntuple_file = sam_file + ".rntuple.root";
                                       ^


// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
for (auto _ : state) {

FILE *original_stdout = stdout;
stdout = fopen(NULL_DEVICE, "w");

samtoramntuple(sam_file.c_str(), rntuple_file.c_str(),
/*index=*/true,
/*split=*/true,
/*cache=*/true,
/*compression_algorithm=*/505,
/*quality_policy=*/0);

// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
fclose(stdout);
stdout = original_stdout;

if (std::filesystem::exists(rntuple_file)) {
auto file_size = std::filesystem::file_size(rntuple_file);
double file_size_mb = static_cast<double>(file_size) / (1024.0 * 1024.0);

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

std::remove(rntuple_file.c_str());
}
}

int main(int argc, char **argv)
{
if (argc > 1) {
std::cout << "Input Files Conversion Benchmark\n";

for (int i = 1; i < argc; i++) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
input_files.emplace_back(argv[i]);
}

for (int i = 0; i < input_files.size(); i++) {
::benchmark::RegisterBenchmark((input_files[i]), BM_SamToRNTupleRealData)
->Args({i})
->Unit(benchmark::kMillisecond);
}

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();

return 0;
}

std::cout << "Individual Conversion Time Benchmark" << std::endl;
std::cout << "====================================" << std::endl;
std::cout << "Measuring TTree and RNTuple conversion times separately" << std::endl;
Expand Down
Loading