mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-08 11:57:53 +08:00
44 lines
907 B
C#
44 lines
907 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
|
|
namespace BetterGenshinImpact.Helpers;
|
|
|
|
public class SpeedTimer
|
|
{
|
|
private readonly Stopwatch _stopwatch;
|
|
|
|
private readonly Dictionary<string, TimeSpan> _timeRecordDic = [];
|
|
|
|
|
|
public SpeedTimer()
|
|
{
|
|
_stopwatch = new Stopwatch();
|
|
_stopwatch.Start();
|
|
}
|
|
|
|
public void Record(string name)
|
|
{
|
|
_timeRecordDic[name] = _stopwatch.Elapsed;
|
|
_stopwatch.Restart();
|
|
}
|
|
|
|
public void DebugPrint()
|
|
{
|
|
var msg = string.Empty;
|
|
foreach (var pair in _timeRecordDic)
|
|
{
|
|
// if (pair.Value.TotalMilliseconds > 0.1)
|
|
// {
|
|
msg += $"{pair.Key}:{pair.Value.TotalMilliseconds}ms,";
|
|
// }
|
|
|
|
}
|
|
|
|
if (msg.Length > 0)
|
|
{
|
|
Debug.WriteLine(msg[..^1]);
|
|
}
|
|
_stopwatch.Stop();
|
|
}
|
|
} |