Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MultiTimer.cs
Go to the documentation of this file.
1using System;
4
5namespace ReLogic.Utilities;
6
7public class MultiTimer
8{
9 private struct TimerData
10 {
11 public readonly double Min;
12
13 public readonly double Max;
14
15 public readonly double Ticks;
16
17 public readonly double Total;
18
19 public double Average => Total / Ticks;
20
21 private TimerData(double min, double max, double ticks, double total)
22 {
23 Min = min;
24 Max = max;
25 Ticks = ticks;
26 Total = total;
27 }
28
29 public TimerData(double startTime)
30 {
31 Min = startTime;
32 Max = startTime;
33 Ticks = 1.0;
35 }
36
37 public TimerData AddTick(double time)
38 {
39 return new TimerData(Math.Min(Min, time), Math.Max(Max, time), Ticks + 1.0, Total + time);
40 }
41 }
42
43 private readonly int _ticksBetweenPrint;
44
46
47 private readonly Stopwatch _timer = new Stopwatch();
48
50
55
56 public void Start()
57 {
58 _timer.Reset();
59 _timer.Start();
60 }
61
62 public void Record(string key)
63 {
64 _timer.Stop();
67 {
69 }
70 else
71 {
73 }
74 _timer.Reset();
75 _timer.Start();
76 }
77
78 public bool StopAndPrint()
79 {
80 _timer.Stop();
83 {
85 Console.WriteLine("Average elapsed time: ");
86 double num = 0.0;
87 int num2 = 0;
89 {
90 num2 = Math.Max(item3.Key.Length, num2);
91 }
93 {
94 TimerData value = item2.Value;
95 string text = new string(' ', num2 - item2.Key.Length);
96 Console.WriteLine(item2.Key + text + " : (Average: " + value.Average.ToString("F4") + " Min: " + value.Min.ToString("F4") + " Max: " + value.Max.ToString("F4") + " from " + (int)value.Ticks + " records)");
97 num += value.Total;
98 }
100 Console.WriteLine("Total : " + (float)num / (float)_ticksBetweenPrint + "ms");
101 return true;
102 }
103 return false;
104 }
105}
void Record(string key)
Definition MultiTimer.cs:62
MultiTimer(int ticksBetweenPrint=100)
Definition MultiTimer.cs:51
readonly Dictionary< string, TimerData > _timerDataMap
Definition MultiTimer.cs:49
readonly Stopwatch _timer
Definition MultiTimer.cs:47
readonly int _ticksBetweenPrint
Definition MultiTimer.cs:43
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static void WriteLine()
Definition Console.cs:733
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
TimerData(double min, double max, double ticks, double total)
Definition MultiTimer.cs:21
double TotalMilliseconds
Definition TimeSpan.cs:46