Repository navigation
Expand file tree
/
Copy pathTimeStat.cpp
More file actions
100 lines (74 loc) · 1.6 KB
/
Copy pathTimeStat.cpp
File metadata and controls
100 lines (74 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
DDS, a bridge double dummy solver.
Copyright (C) 2006-2014 by Bo Haglund /
2014-2018 by Bo Haglund & Soren Hein.
See LICENSE and README.
*/
#include <iostream>
#include <iomanip>
#include <sstream>
#include <math.h>
#include "TimeStat.h"
TimeStat::TimeStat()
{
TimeStat::Reset();
}
TimeStat::~TimeStat()
{
}
void TimeStat::Reset()
{
number = 0;
cum = 0;
cumsq = 0.;
}
void TimeStat::Set(const int timeUser)
{
number = 1;
cum = timeUser;
cumsq = static_cast<double>(timeUser) * static_cast<double>(timeUser);
}
void TimeStat::Set(
const int timeUser,
const double timesq)
{
number = 1;
cum = timeUser;
cumsq = timesq;
}
void TimeStat::operator +=(const TimeStat& add)
{
number += add.number;
cum += add.cum;
cumsq += add.cumsq;
}
bool TimeStat::Used() const
{
return (number > 0);
}
string TimeStat::Header() const
{
stringstream ss;
ss << setw(5) << right << "n" <<
setw(9) << right << "Number" <<
setw(13) << "Cum time" <<
setw(13) << "Average" <<
setw(13) << "Sdev" <<
setw(13) << "Sdev/mu" << "\n";
return ss.str();
}
string TimeStat::Line() const
{
if (number == 0)
return "";
double avg = static_cast<double>(cum) / static_cast<double>(number);
double arg = (cumsq / static_cast<double>(number)) - avg * avg;
double sdev = (arg >= 0. ? sqrt(arg) : 0.);
stringstream ss;
ss << setw(9) << right << number <<
setw(13) << cum <<
setw(13) << setprecision(0) << fixed << avg <<
setw(13) << setprecision(0) << fixed << sdev <<
setw(13) << setprecision(2) << fixed << sdev/avg << "\n";
return ss.str();
}