Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Stopwatch.cs
Go to the documentation of this file.
2
3namespace System.Diagnostics;
4
5public class Stopwatch
6{
7 private long _elapsed;
8
9 private long _startTimeStamp;
10
11 private bool _isRunning;
12
13 public static readonly long Frequency = QueryPerformanceFrequency();
14
15 public static readonly bool IsHighResolution = true;
16
17 private static readonly double s_tickFrequency = 10000000.0 / (double)Frequency;
18
19 public bool IsRunning => _isRunning;
20
22
24
26
27 public Stopwatch()
28 {
29 Reset();
30 }
31
32 public void Start()
33 {
34 if (!_isRunning)
35 {
37 _isRunning = true;
38 }
39 }
40
41 public static Stopwatch StartNew()
42 {
43 Stopwatch stopwatch = new Stopwatch();
44 stopwatch.Start();
45 return stopwatch;
46 }
47
48 public void Stop()
49 {
50 if (_isRunning)
51 {
52 long timestamp = GetTimestamp();
53 long num = timestamp - _startTimeStamp;
54 _elapsed += num;
55 _isRunning = false;
56 if (_elapsed < 0)
57 {
58 _elapsed = 0L;
59 }
60 }
61 }
62
63 public void Reset()
64 {
65 _elapsed = 0L;
66 _isRunning = false;
68 }
69
70 public void Restart()
71 {
72 _elapsed = 0L;
74 _isRunning = true;
75 }
76
77 public static long GetTimestamp()
78 {
80 }
81
82 private long GetRawElapsedTicks()
83 {
84 long num = _elapsed;
85 if (_isRunning)
86 {
87 long timestamp = GetTimestamp();
88 long num2 = timestamp - _startTimeStamp;
89 num += num2;
90 }
91 return num;
92 }
93
95 {
96 return (long)((double)GetRawElapsedTicks() * s_tickFrequency);
97 }
98
99 private unsafe static long QueryPerformanceFrequency()
100 {
101 System.Runtime.CompilerServices.Unsafe.SkipInit(out long result);
103 return result;
104 }
105
106 private unsafe static long QueryPerformanceCounter()
107 {
108 System.Runtime.CompilerServices.Unsafe.SkipInit(out long result);
110 return result;
111 }
112}
static unsafe BOOL QueryPerformanceFrequency(long *lpFrequency)
static unsafe BOOL QueryPerformanceCounter(long *lpPerformanceCount)
static Stopwatch StartNew()
Definition Stopwatch.cs:41
static readonly long Frequency
Definition Stopwatch.cs:13
static readonly bool IsHighResolution
Definition Stopwatch.cs:15
static unsafe long QueryPerformanceCounter()
Definition Stopwatch.cs:106
static readonly double s_tickFrequency
Definition Stopwatch.cs:17
static unsafe long QueryPerformanceFrequency()
Definition Stopwatch.cs:99