From a5b72f7ae69e5a28434fca02faba6f48ca0d09a1 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 8 Jan 2016 10:57:53 -0800 Subject: [PATCH] read benchmark: accept a filename as an argument On my Macbook Pro, reading from standard input incurs a bunch of locking overhead, which complicates profiling and (IMO) adds noise to results. This adds the option to read from a file, which doesn't incur this overhead. --- util/read.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/util/read.cpp b/util/read.cpp index fabee1a..4734e88 100644 --- a/util/read.cpp +++ b/util/read.cpp @@ -1,3 +1,4 @@ +#include #include #include "yaml-cpp/emitterstyle.h" @@ -25,9 +26,19 @@ class NullEventHandler : public YAML::EventHandler { virtual void OnMapEnd() {} }; -int main() { - YAML::Parser parser(std::cin); +void run(YAML::Parser& parser) { NullEventHandler handler; parser.HandleNextDocument(handler); +} + +int main(int argc, char** argv) { + if (argc > 1) { + std::ifstream in(argv[1]); + YAML::Parser parser(in); + run(parser); + } else { + YAML::Parser parser(std::cin); + run(parser); + } return 0; }