Skip to content

Commit

Permalink
refactor: remove stopwatches
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Aug 18, 2023
1 parent 8ee9db8 commit 5eaef16
Showing 1 changed file with 2 additions and 37 deletions.
39 changes: 2 additions & 37 deletions MHFZ_Overlay/Services/TimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace MHFZ_Overlay.Services;
using NLog;

/// <summary>
/// A service for doing time and date manipulation.
/// A service for doing time and date manipulation. Consult the benchmarks project for the performance.
/// </summary>
public static class TimeService
{
Expand All @@ -40,41 +40,6 @@ public static string TestTimerMethods(decimal timeDefInt)
{
decimal timeInt = timeDefInt;
var maxTime = timeDefInt.ToString(TimeFormats.HoursMinutesSecondsMilliseconds, CultureInfo.InvariantCulture);

var stopwatch = new Stopwatch();
stopwatch.Start();
for (decimal i = timeDefInt; i > 0; i--)
{
StringBuilderTimer(timeInt, timeDefInt);
timeInt--;
}

stopwatch.Stop();
var stringBuilderTime = $"Total execution time for StringBuilderTimer: {stopwatch.ElapsedMilliseconds} ms";

timeInt = timeDefInt;
stopwatch.Start();
for (decimal i = timeDefInt; i > 0; i--)
{
TimeSpanTimer(timeInt, timeDefInt);
timeInt--;
}

stopwatch.Stop();
var timeSpanTime = $"Total execution time for TimeSpanTimer: {stopwatch.ElapsedMilliseconds} ms";

timeInt = timeDefInt;
stopwatch.Start();
for (decimal i = timeDefInt; i > 0; i--)
{
FastestTimer(timeDefInt - timeInt);
timeInt--;
}

stopwatch.Stop();
var fastestTime = $"Total execution time for FastestTimer: {stopwatch.ElapsedMilliseconds} ms";

timeInt = timeDefInt;
for (decimal i = timeDefInt; i > 0M; i--)
{
var timer1Result = StringBuilderTimer(timeInt, timeDefInt);
Expand All @@ -83,7 +48,7 @@ public static string TestTimerMethods(decimal timeDefInt)

if (timer1Result != timer2Result || fastestResult != timer1Result || fastestResult != timer2Result)
{
return $"timeDefInt: {timeDefInt} ({maxTime}) timeInt: {timeInt} | StringBuilder: {timer1Result} | TimeSpan: {timer2Result} | Fastest: {fastestResult} | {fastestTime} | {stringBuilderTime} | {timeSpanTime}";
return $"timeDefInt: {timeDefInt} ({maxTime}) timeInt: {timeInt} | StringBuilder: {timer1Result} | TimeSpan: {timer2Result}";
}

timeInt--;
Expand Down

0 comments on commit 5eaef16

Please sign in to comment.