-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicToc.cs
66 lines (49 loc) · 1.55 KB
/
TicToc.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
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace RandomWalkFramework {
public class TicToc {
public static TicToc Tic() {
LastReference = new TicToc();
return LastReference;
}
public static TicToc Tic(string LogPath) {
LastReference = new TicToc(LogPath);
return LastReference;
}
public static TicToc Tic(string Name, bool supressConsole) {
LastReference = new TicToc(Name, supressConsole);
return LastReference;
}
public static void LToc() { if (LastReference != null) LastReference.Toc(); }
private static TicToc LastReference = null;
private string MethodName;
private bool SupressConsole;
private string LogPath;
private TicToc(string LogPath, bool supressConsole) {
if (!supressConsole) {
StackTrace stackTrace = new StackTrace();
MethodName = stackTrace.GetFrame(3).GetMethod().Name;
Console.WriteLine();
Console.Write("Tic from {0}...", MethodName);
}
Ticks = DateTime.Now.Ticks;
this.LogPath = LogPath;
this.SupressConsole = supressConsole;
}
private TicToc(string name)
: this(name, false) {
}
private TicToc()
: this(null, false) {
}
public void Toc() {
if (!SupressConsole) { Console.WriteLine("toc from {1} after {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - Ticks), MethodName); }
if (LogPath != null) { File.AppendAllText(LogPath, TimeSpan.FromTicks(DateTime.Now.Ticks - Ticks).TotalMilliseconds.ToString() + Environment.NewLine); }
}
private long Ticks = 0;
}
}