mirror of
https://github.com/netchx/netch.git
synced 2026-03-16 17:53:17 +08:00
27 lines
668 B
C#
27 lines
668 B
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace Netch.Models
|
|
{
|
|
public class LogStopwatch
|
|
{
|
|
public LogStopwatch(string message)
|
|
{
|
|
_stopwatch = Stopwatch.StartNew();
|
|
Console.WriteLine($"Start {message} LogStopwatch");
|
|
}
|
|
|
|
private readonly Stopwatch _stopwatch;
|
|
|
|
public void Log(string name,bool stop = false)
|
|
{
|
|
if (!_stopwatch.IsRunning)
|
|
throw new Exception();
|
|
|
|
_stopwatch.Stop();
|
|
Console.WriteLine($"{name} LogStopwatch: {_stopwatch.ElapsedMilliseconds}");
|
|
if(!stop)
|
|
_stopwatch.Start();
|
|
}
|
|
}
|
|
} |