Skip to content

Commit f148e54

Browse files
Add benchmarker
1 parent a945416 commit f148e54

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/Benchmarker.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Diagnostics;
3+
using Oxide.Pooling;
4+
5+
namespace Oxide;
6+
7+
public class Benchmarker : IDisposable
8+
{
9+
private string _input;
10+
private Stopwatch _stopwatch;
11+
12+
public static Benchmarker Start(string input)
13+
{
14+
Console.WriteLine($"Started benchmarking {input}");
15+
16+
Benchmarker benchmarker = PoolFactory<Benchmarker>.Shared.Take();
17+
benchmarker._input = input;
18+
benchmarker._stopwatch = PoolFactory<Stopwatch>.Shared.Take();
19+
benchmarker._stopwatch.Start();
20+
return benchmarker;
21+
}
22+
23+
public void Dispose()
24+
{
25+
_stopwatch.Stop();
26+
27+
Console.WriteLine($"{_input} took {_stopwatch.Elapsed} [{_stopwatch.ElapsedTicks} ticks]");
28+
29+
PoolFactory<Stopwatch>.Shared.Return(_stopwatch);
30+
PoolFactory<Benchmarker>.Shared.Return(this);
31+
32+
_input = null;
33+
_stopwatch = null;
34+
}
35+
}

0 commit comments

Comments
 (0)