8 #include <boost/program_options.hpp>
10 #include "artdaq/DAQdata/Globals.hh"
11 namespace bpo = boost::program_options;
13 std::string formatTime(
double time)
16 o << std::fixed << std::setprecision(3);
18 o << static_cast<int>(time / 60) <<
" m " << time - 60 * static_cast<int>(time / 60) <<
" s";
42 int main(
int argc,
char *argv[])
44 std::ostringstream descstr;
46 <<
" <-l test loops> [csutdi]";
47 bpo::options_description desc(descstr.str());
48 desc.add_options()(
"loops,l", bpo::value<size_t>(),
"Number of times to run each test")(
"C,c",
"Run TRACEC test")(
"S,s",
"Run TRACES test")(
"U,u",
"Run TRACE_ test")(
"T,t",
"Run TRACE_STREAMER test")(
"D,d",
"Run TLOG_DEBUG test")(
"I,i",
"Run TLOG_INFO test")(
"console,x",
"Enable MessageFacility output to console")(
"help,h",
"produce help message");
49 bpo::variables_map vm;
52 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
55 catch (bpo::error
const &e)
57 std::cerr <<
"Exception from command line processing in " << argv[0]
58 <<
": " << e.what() <<
"\n";
63 std::cout << desc << std::endl;
66 if (!vm.count(
"loops"))
68 std::cerr <<
"Exception from command line processing in " << argv[0]
69 <<
": no loop count given.\n"
70 <<
"For usage and an options list, please do '"
71 << argv[0] <<
" --help"
75 size_t loops = vm[
"loops"].as<
size_t>();
77 artdaq::configureMessageFacility(
"tracemf", vm.count(
"console"));
81 std::cout <<
"Starting TRACEC test" << std::endl;
82 auto start = std::chrono::steady_clock::now();
83 for (
size_t l = 0; l < loops; ++l)
85 TRACE(TLVL_DEBUG,
"Test TRACEC with an int %i and a float %.1f", 42, 5.56);
87 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
88 std::cout <<
"TRACEC test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
93 std::cout <<
"Starting TRACES test" << std::endl;
94 auto start = std::chrono::steady_clock::now();
95 for (
size_t l = 0; l < loops; ++l)
97 std::string test =
"Test TRACE with an int %d";
98 std::string test2 =
" and a float %.1f";
99 TRACE(TLVL_DEBUG, test + test2, 42, 5.56);
101 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
102 std::cout <<
"TRACES test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
107 std::cout <<
"Starting TRACE_ test" << std::endl;
108 auto start = std::chrono::steady_clock::now();
109 for (
size_t l = 0; l < loops; ++l)
111 TRACEN_(
"tracemf", TLVL_DEBUG,
"Test TRACE_ with an int " << 42 <<
" and a float %.1f", 5.56);
113 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
114 std::cout <<
"TRACE_ test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
119 std::cout <<
"Starting TLOG_DEBUG test" << std::endl;
120 auto start = std::chrono::steady_clock::now();
121 for (
size_t l = 0; l < loops; ++l)
123 TLOG_DEBUG(
"tracemf") <<
"Test TLOG_DEBUG with an int " << 42 <<
" and a float " << std::setprecision(1) << 5.56 <<
", and another float " << 7.3 << TRACE_ENDL;
125 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
126 std::cout <<
"TLOG_DEBUG test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
131 std::cout <<
"Starting TLOG_INFO test" << std::endl;
132 auto start = std::chrono::steady_clock::now();
133 for (
size_t l = 0; l < loops; ++l)
135 TLOG_INFO(
"tracemf") <<
"Test TLOG_INFO with an int " << 42 <<
" and a float " << std::setprecision(1) << 5.56 <<
", and another float " << std::fixed << 7.3 << TRACE_ENDL;
137 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
138 std::cout <<
"TLOG_INFO test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;