2014-12-15 22:58:49 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2015-11-02 21:43:09 +08:00
|
|
|
|
using Wox.Infrastructure.Logger;
|
2014-12-15 22:58:49 +08:00
|
|
|
|
|
|
|
|
|
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;
|
2014-12-15 22:58:49 +08:00
|
|
|
|
|
|
|
|
|
public Timeit(string name)
|
|
|
|
|
{
|
2015-11-02 08:04:05 +08:00
|
|
|
|
_name = name;
|
|
|
|
|
_stopwatch.Start();
|
2014-12-15 22:58:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-02 08:04:05 +08:00
|
|
|
|
public long Current
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
_stopwatch.Stop();
|
|
|
|
|
long seconds = _stopwatch.ElapsedMilliseconds;
|
|
|
|
|
_stopwatch.Start();
|
|
|
|
|
return seconds;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-12-15 22:58:49 +08:00
|
|
|
|
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);
|
2014-12-15 22:58:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|