38 lines
813 B
C#
38 lines
813 B
C#
using System.Diagnostics;
|
|
using UnityEngine;
|
|
|
|
namespace DebuggingEssentials
|
|
{
|
|
public class Benchmark
|
|
{
|
|
public static FastCacheList<Benchmark> benchmarks = new FastCacheList<Benchmark>(128);
|
|
|
|
public Stopwatch stopwatch = new Stopwatch();
|
|
|
|
public string text;
|
|
|
|
private float minMiliSeconds;
|
|
|
|
public static Benchmark Start(string text, float minMiliSeconds = -1f)
|
|
{
|
|
Benchmark item = benchmarks.GetItem();
|
|
item.minMiliSeconds = minMiliSeconds;
|
|
item.text = text;
|
|
item.stopwatch.Reset();
|
|
item.stopwatch.Start();
|
|
return item;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
stopwatch.Stop();
|
|
float num = (float)stopwatch.Elapsed.Ticks / (float)Stopwatch.Frequency * 1000f;
|
|
if (num > minMiliSeconds)
|
|
{
|
|
UnityEngine.Debug.Log(text + " " + num + " ms");
|
|
benchmarks.Add(this);
|
|
}
|
|
}
|
|
}
|
|
}
|