Files
PowerToys/Wox.Infrastructure/Timeit.cs

44 lines
1.0 KiB
C#
Raw Normal View History

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