13 : m_tool_name(tool_name)
32 m_results.push_back(times);
44 double min_cpu = 9999, max_cpu = -9999, tot_cpu = 0;
45 double min_real = 9999, max_real = -9999, tot_real = 0;
49 const int n = m_results.size();
50 for(
size_t i = 0; i < n; i++) {
51 cpu = m_results[i].cpu_time;
52 real = m_results[i].real_time;
57 min_cpu = cpu < min_cpu ? cpu : min_cpu;
58 min_real = real < min_real ? real : min_real;
60 max_cpu = cpu > max_cpu ? cpu : max_cpu;
61 max_real = real > max_real ? real : max_real;
64 if(output_file.length()) {
65 double min = std::min(min_cpu, min_real);
66 double max = std::max(max_cpu, max_real);
67 TH1D hcpu (
"hcpu",
";Time (s);Runs", sqrt(n), min, max);
68 TH1D hreal(
"hreal",
";Time (s);Runs", sqrt(n), min, max);
69 for(
size_t i = 0; i < n; i++) {
70 cpu_var += pow((m_results[i].cpu_time-tot_cpu/n),2.)/(n-1.);
71 hcpu .Fill(m_results[i].cpu_time);
72 real_var += pow((m_results[i].real_time-tot_real/n),2.)/(n-1.);
73 hreal.Fill(m_results[i].real_time);
76 hcpu.GetYaxis()->SetRangeUser(0, 1.05 * std::max(hcpu.GetMaximum(), hreal.GetMaximum()));
78 hreal.SetLineColor(kRed);
80 TLegend leg(0.8, 0.9, 1, 1);
81 leg.AddEntry(&hcpu,
"CPU time",
"L");
82 leg.AddEntry(&hreal,
"Real time",
"L");
84 c.SaveAs(output_file.c_str());
89 ss << m_tool_name <<
"::" << method_name <<
"() run timing stats:" << std::endl
90 <<
" CPU Time (s): Total = " << tot_cpu << std::endl
91 <<
" Average = " << tot_cpu / (double)n << std::endl
92 <<
" Sample standard deviation = " << sqrt(cpu_var)
93 <<
" over " << n <<
" runs" << std::endl
94 <<
" Range of " << min_cpu <<
" to " << max_cpu << std::endl
95 <<
" Real Time (s): Total = " << tot_real << std::endl
96 <<
" Average = " << tot_real / (double)n << std::endl
97 <<
" Sample standard deviation = " << sqrt(real_var)
98 <<
" over " << n <<
" runs" << std::endl
99 <<
" Range of " << min_real <<
" to " << max_real << std::endl;
std::string Result(std::string method_name, std::string output_file="")
void Start()
Start the stopwatch.
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time.
Stopwatch(const char *tool_name)
void Reset()
Stop the stopwatch, and clear the results vector.