Flow.Launcher/Flow.Launcher.Infrastructure/Stopwatch.cs

64 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Infrastructure.Logger;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Infrastructure
{
public static class Stopwatch
{
/// <summary>
/// This stopwatch will appear only in Debug mode
/// </summary>
2017-01-24 00:24:20 +00:00
public static long Debug(string message, Action action)
{
2016-11-30 00:31:31 +00:00
var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
action();
2016-11-30 00:31:31 +00:00
stopWatch.Stop();
var milliseconds = stopWatch.ElapsedMilliseconds;
2017-01-24 00:24:20 +00:00
string info = $"{message} <{milliseconds}ms>";
Log.Debug(info);
2016-11-30 00:31:31 +00:00
return milliseconds;
}
/// <summary>
/// This stopwatch will appear only in Debug mode
/// </summary>
public static async Task<long> DebugAsync(string message, Func<Task> action)
{
var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
await action();
stopWatch.Stop();
var milliseconds = stopWatch.ElapsedMilliseconds;
string info = $"{message} <{milliseconds}ms>";
Log.Debug(info);
return milliseconds;
}
2017-01-24 00:24:20 +00:00
public static long Normal(string message, Action action)
{
var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
action();
stopWatch.Stop();
var milliseconds = stopWatch.ElapsedMilliseconds;
2017-01-24 00:24:20 +00:00
string info = $"{message} <{milliseconds}ms>";
Log.Info(info);
return milliseconds;
}
public static async Task<long> NormalAsync(string message, Func<Task> action)
{
var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
await action();
stopWatch.Stop();
var milliseconds = stopWatch.ElapsedMilliseconds;
string info = $"{message} <{milliseconds}ms>";
Log.Info(info);
return milliseconds;
}
}
}