namespace ACE.Common.Performance { public class TimedEventHistory { /// /// Last event duration in seconds /// public double LastEvent { get; private set; } public long TotalEvents { get; private set; } public double TotalSeconds { get; private set; } /// /// Longest event duration in seconds /// public double LongestEvent { get; private set; } /// /// Shortest event duration in seconds /// public double ShortestEvent { get; private set; } /// /// Average event duration in seconds /// public double AverageEventDuration => TotalEvents == 0 ? 0 : (TotalSeconds / TotalEvents); public void RegisterEvent(double totalSeconds) { LastEvent = totalSeconds; TotalEvents++; TotalSeconds += LastEvent; if (LastEvent > LongestEvent) LongestEvent = LastEvent; if (TotalEvents == 1 || LastEvent < ShortestEvent) ShortestEvent = LastEvent; } public void ClearHistory() { LastEvent = 0; TotalEvents = 0; TotalSeconds = 0; LongestEvent = 0; ShortestEvent = 0; } public override string ToString() { return $"Total Events: {TotalEvents:N0}, Average: {AverageEventDuration:N4} s, Longest: {LongestEvent:N4} s, Shortest: {ShortestEvent:N4} s, Last: {LastEvent:N4} s"; } } }