2222#include " itkHighPriorityRealTimeProbe.h"
2323#include " itkHighPriorityRealTimeProbesCollector.h"
2424
25+ #if defined(PERFORMANCE_BENCHMARKING_USE_ITKWASM)
26+ # include " itkPipeline.h"
27+ # include " itkOutputTextStream.h"
28+ #endif
29+
2530#include < sstream>
2631#include < fstream>
2732#include " PerformanceBenchmarkingUtilities.h"
@@ -122,16 +127,46 @@ time_it(unsigned int threads, unsigned int iterations)
122127int
123128main (int argc, char * argv[])
124129{
125- if (argc > 3 )
130+ bool noPrintStdout = false ;
131+ bool expandedReport = false ;
132+ bool noPrintSystemInfo = false ;
133+ bool noPrintReportHead = false ;
134+ constexpr int iterationsDefault = 500 ;
135+ const int threadsDefault = MultiThreaderName::GetGlobalDefaultNumberOfThreads ();
136+
137+ #if defined(PERFORMANCE_BENCHMARKING_USE_ITKWASM)
138+ itk::wasm::Pipeline pipeline (" thread-overhead" , " Estimate the overhead cost per-thread." , argc, argv);
139+
140+ itk::wasm::OutputTextStream timingsJson;
141+ pipeline.add_option (" timings" , timingsJson, " Internal timings" )->type_name (" OUTPUT_JSON" );
142+
143+ pipeline.add_flag (" --no-print-stdout" , noPrintStdout, " Do not print to stdout." );
144+ pipeline.add_flag (" --expanded-report" , expandedReport, " Print an expanded report." );
145+ pipeline.add_flag (" --no-print-system-info" , noPrintSystemInfo, " Do not print system information." );
146+ pipeline.add_flag (" --no-print-report-head" , noPrintReportHead, " Do not print the report header." );
147+
148+ int iterations = iterationsDefault;
149+ pipeline.add_option (" --iterations" , iterations, " Number of iterations to run." );
150+
151+ int threads = threadsDefault;
152+ pipeline.add_option (" --threads" , threads, " Number of threads to use." );
153+
154+ ITK_WASM_PARSE (pipeline);
155+
156+ std::ostream & timingsStream = timingsJson.Get ();
157+ #else
158+ if (argc > 5 )
126159 {
127160 std::cerr << " Usage: " << std::endl;
128- std::cerr << argv[0 ] << " timingsFile [iterations [ threads]]" << std::endl;
161+ std::cerr << argv[0 ] << " timingsFile [-- iterations iterations [--threads threads]]" << std::endl;
129162 return EXIT_FAILURE;
130163 }
131164
132165 const std::string timingsFileName = ReplaceOccurrence (argv[1 ], " __DATESTAMP__" , PerfDateStamp ());
133- const int iterations = (argc > 2 ) ? std::stoi (argv[2 ]) : 500 ;
134- const int threads = (argc > 3 ) ? std::stoi (argv[3 ]) : MultiThreaderName::GetGlobalDefaultNumberOfThreads ();
166+ auto timingsStream = std::ofstream (timingsFileName, std::ios_base::out);
167+ const int iterations = (argc > 3 ) ? std::stoi (argv[3 ]) : iterationsDefault;
168+ const int threads = (argc > 5 ) ? std::stoi (argv[5 ]) : threadsDefault;
169+ #endif
135170
136171 if (threads == 1 )
137172 {
@@ -142,7 +177,8 @@ main(int argc, char * argv[])
142177 ProbeType t1 = time_it (1 , iterations);
143178 ProbeType t2 = time_it (threads, iterations);
144179
145- WriteExpandedReport (timingsFileName, collector, true , true , false );
180+ WriteExpandedReport (
181+ timingsStream, collector, !noPrintStdout, expandedReport, !noPrintSystemInfo, !noPrintReportHead, false );
146182
147183 double cost = (t2.GetMinimum () - t1.GetMinimum ()) / (threads - 1.0 );
148184
0 commit comments