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
|
|
|
|
|
{
|
2015-11-05 05:49:36 +08:00
|
|
|
|
public static class Stopwatch
|
2014-12-15 22:58:49 +08:00
|
|
|
|
{
|
2015-11-05 05:35:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This stopwatch will appear only in Debug mode
|
|
|
|
|
/// </summary>
|
2015-11-05 05:49:36 +08:00
|
|
|
|
public static void Debug(string name, Action action)
|
2014-12-15 22:58:49 +08:00
|
|
|
|
{
|
2015-11-05 05:35:04 +08:00
|
|
|
|
#if DEBUG
|
2015-11-05 05:49:36 +08:00
|
|
|
|
Normal(name, action);
|
2015-11-05 05:35:04 +08:00
|
|
|
|
#else
|
|
|
|
|
action();
|
|
|
|
|
#endif
|
2014-12-15 22:58:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-05 05:35:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This stopwatch will also appear only in Debug mode
|
|
|
|
|
/// </summary>
|
2015-11-05 05:49:36 +08:00
|
|
|
|
public static long Normal(string name, Action action)
|
2014-12-15 22:58:49 +08:00
|
|
|
|
{
|
2015-11-05 05:49:36 +08:00
|
|
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
2015-11-05 05:35:04 +08:00
|
|
|
|
stopWatch.Start();
|
|
|
|
|
action();
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
2015-11-08 01:32:58 +08:00
|
|
|
|
string info = $"{name} : {milliseconds}ms";
|
|
|
|
|
Log.Debug(info);
|
2015-11-05 05:35:04 +08:00
|
|
|
|
return milliseconds;
|
2014-12-15 22:58:49 +08:00
|
|
|
|
}
|
2015-11-05 05:35:04 +08:00
|
|
|
|
|
2014-12-15 22:58:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|