mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Better name
Timeit.Stopwatch -> Stopwatch.Normal Timeit.StopwatchDebug -> Stopwatch.Debug
This commit is contained in:
44
Wox.Infrastructure/Stopwatch.cs
Normal file
44
Wox.Infrastructure/Stopwatch.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
public static class Stopwatch
|
||||
{
|
||||
/// <summary>
|
||||
/// This stopwatch will appear only in Debug mode
|
||||
/// </summary>
|
||||
public static void Debug(string name, Action action)
|
||||
{
|
||||
#if DEBUG
|
||||
Normal(name, action);
|
||||
#else
|
||||
action();
|
||||
#endif
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private static void WriteTimeInfo(string name, long milliseconds)
|
||||
{
|
||||
string info = $"{name} : {milliseconds}ms";
|
||||
System.Diagnostics.Debug.WriteLine(info);
|
||||
Log.Info(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This stopwatch will also appear only in Debug mode
|
||||
/// </summary>
|
||||
public static long Normal(string name, Action action)
|
||||
{
|
||||
var stopWatch = new System.Diagnostics.Stopwatch();
|
||||
stopWatch.Start();
|
||||
action();
|
||||
stopWatch.Stop();
|
||||
var milliseconds = stopWatch.ElapsedMilliseconds;
|
||||
WriteTimeInfo(name, milliseconds);
|
||||
return milliseconds;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user