PowerToys/Wox.Infrastructure/Timeit.cs

39 lines
864 B
C#
Raw Normal View History

using System;
using System.Diagnostics;
2015-11-02 21:43:09 +08:00
using Wox.Infrastructure.Logger;
namespace Wox.Infrastructure
{
public class Timeit : IDisposable
{
2015-11-02 08:04:05 +08:00
private readonly Stopwatch _stopwatch = new Stopwatch();
private readonly string _name;
public Timeit(string name)
{
2015-11-02 08:04:05 +08:00
_name = name;
_stopwatch.Start();
}
2015-11-02 08:04:05 +08:00
public long Current
{
get
{
_stopwatch.Stop();
long seconds = _stopwatch.ElapsedMilliseconds;
_stopwatch.Start();
return seconds;
}
}
public void Dispose()
{
2015-11-02 08:04:05 +08:00
_stopwatch.Stop();
2015-11-02 21:43:09 +08:00
string info = _name + " : " + _stopwatch.ElapsedMilliseconds + "ms";
Debug.WriteLine(info);
Log.Info(info);
}
}
}