Skip to content

Commit

Permalink
Performance monitoring tools
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Oct 6, 2023
1 parent bea0831 commit b90be25
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Core/Logging.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Reflection;
using System.Diagnostics;

using log4net;
using log4net.Config;
using log4net.Core;
Expand Down Expand Up @@ -40,5 +42,31 @@ public static void Initialize()
}
}
}

public static void WithTimeElapsed(Action<TimeSpan> elapsedCallback,
Action toMeasure)
{
var sw = new Stopwatch();
sw.Start();

toMeasure();

sw.Stop();
elapsedCallback(sw.Elapsed);
}

public static T WithTimeElapsed<T>(Action<TimeSpan> elapsedCallback,
Func<T> toMeasure)
{
var sw = new Stopwatch();
sw.Start();

T val = toMeasure();

sw.Stop();
elapsedCallback(sw.Elapsed);

return val;
}
}
}

0 comments on commit b90be25

Please sign in to comment.