forked from twobitcoder101/Flat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counter.cs
55 lines (45 loc) · 1.15 KB
/
Counter.cs
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
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Flat
{
public sealed class Counter
{
private int count;
private Stopwatch watch;
private double interval;
public double CountPerInterval
{
get { return (double)this.count / (this.watch.Elapsed.TotalSeconds / interval); }
}
public double CountTotal
{
get { return this.count; }
}
public Counter(double interval)
{
interval = FlatMath.Clamp(interval, 0.1d, 10d);
this.count = 0;
this.watch = new Stopwatch();
this.interval = interval;
}
public void Start()
{
this.watch.Start();
}
public void Restart()
{
this.count = 0;
this.watch.Restart();
}
public void Stop()
{
this.count = 0;
this.watch.Stop();
}
public void IncCount(int amount = 1)
{
this.count += amount;
}
}
}