2 using System.Collections.Generic;
5 using DirectOutput.General.Generic;
7 namespace DirectOutput.General.Statistics
11 private DateTime StartTime=DateTime.MinValue;
13 public void MeasurementStart()
15 StartTime = DateTime.Now;
18 public void MeasurementStop()
20 if (StartTime != DateTime.MinValue)
22 AddDuration(DateTime.Now - StartTime);
23 StartTime = DateTime.MinValue;
27 private string _GroupName=
"<Not grouped>";
29 public string GroupName
31 get {
return _GroupName; }
32 set { _GroupName= value; }
36 TimeSpan _TotalDuration =
new TimeSpan(0);
38 public TimeSpan TotalDuration
40 get {
return _TotalDuration; }
43 public long ValuesCount {
get;
private set; }
45 public TimeSpan AverageDuration
49 if (ValuesCount == 0)
return new TimeSpan(0);
51 return TimeSpan.FromTicks(_TotalDuration.Ticks / ValuesCount);
56 List<TimeSpan> _MaxDurations =
new List<TimeSpan>();
58 public TimeSpan MaxDuration
62 return MaxDurations.Max();
66 public List<TimeSpan> MaxDurations
68 get {
return _MaxDurations; }
69 private set { _MaxDurations = value; }
73 List<TimeSpan> _MinDurations =
new List<TimeSpan>();
75 public TimeSpan MinDuration
79 return MinDurations.Min();
84 public List<TimeSpan> MinDurations
86 get {
return _MinDurations; }
87 private set { _MinDurations = value; }
92 private TimeSpan MaxBoundary;
93 private TimeSpan MinBoundary;
94 private bool MinMaxBufferFull =
false;
95 public void AddDuration(TimeSpan Duration)
97 _TotalDuration += Duration;
99 if (!MinMaxBufferFull)
101 MaxDurations.Add(Duration);
102 MinDurations.Add(Duration);
103 if (MaxDurations.Count > 9)
105 MaxBoundary = MaxDurations.Min();
106 MinBoundary = MinDurations.Max();
107 MinMaxBufferFull =
true;
113 if (Duration.CompareTo(MaxBoundary) > 0)
115 MaxDurations.Remove(MaxBoundary);
116 MaxDurations.Add(Duration);
117 MaxBoundary = MaxDurations.Min();
119 if (Duration.CompareTo(MinBoundary) < 0)
121 MinDurations.Remove(MinBoundary);
122 MinDurations.Add(Duration);
123 MinBoundary = MinDurations.Max();
133 public override string ToString()
136 string S =
"{0}, ".Build(Name);
137 S+=
"Values count: {0}".Build(ValuesCount);
140 S +=
", Total: {0}, ".Build(TotalDuration.Format());
141 S +=
"Avg.: {0}, ".Build(AverageDuration.Format());
142 S +=
"Min.: {0}, ".Build(MinDuration.Format());
143 S +=
"Max.: {0}".Build(MaxDuration.Format());