-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformanceTimer.cs
More file actions
48 lines (43 loc) · 1.18 KB
/
PerformanceTimer.cs
File metadata and controls
48 lines (43 loc) · 1.18 KB
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
using System;
using UnityEngine;
namespace Minerva.Module
{
/// <summary>
/// A simple clock by using statement
/// </summary>
public struct PerformanceTimer : IDisposable
{
private bool echo;
private DateTime start;
private string message;
private Func<string> provider;
public PerformanceTimer(bool echo)
{
this.echo = echo;
this.start = DateTime.Now;
this.message = "Section took {0} ms";
this.provider = null;
}
public PerformanceTimer(bool echo, string message)
{
this.echo = echo;
this.start = DateTime.Now;
this.message = message;
this.provider = null;
}
public PerformanceTimer(bool echo, Func<string> provider)
{
this.echo = echo;
this.start = DateTime.Now;
this.message = null;
this.provider = provider;
}
public void Dispose()
{
if (echo)
{
Debug.LogFormat(this.message ?? provider(), (DateTime.Now.Ticks - start.Ticks) / 10000f);
}
}
}
}