forked from GeneROOT/ramtools
-
Notifications
You must be signed in to change notification settings - Fork 1
Add region query benchmark #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #include <benchmark/benchmark.h> | ||
| #include "generate_sam_benchmark.h" | ||
| #include "ramcore/SamToTTree.h" | ||
| #include "ramcore/SamToNTuple.h" | ||
| #include <string> | ||
| #include <cstdio> | ||
|
|
||
| #ifdef _WIN32 | ||
| #define NULL_DEVICE "NUL" | ||
| #else | ||
| #define NULL_DEVICE "/dev/null" | ||
| #endif | ||
|
|
||
| // Forward declarations | ||
| 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"; | ||
|
|
||
| // Convert once before timing | ||
| suppress_output(); | ||
| samtoram(sam_file_.c_str(), root_file.c_str(), true, true, true, 1, 0); | ||
| restore_output(); | ||
|
|
||
| // Benchmark only the query performance | ||
| 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"; | ||
|
|
||
| // Convert once before timing | ||
| suppress_output(); | ||
| samtoramntuple(sam_file_.c_str(), root_file.c_str(), true, true, true, 505, 0); | ||
| restore_output(); | ||
|
|
||
| // Benchmark only the query performance | ||
| 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(); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, this was already put somewhere. Can we make sure we reuse code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to address this.