Skip to content

Commit

Permalink
MeasureDurationResult incorrect when running in linux (#4785)
Browse files Browse the repository at this point in the history
Use the Stopwatch.Frequency when calculating the milli and micro seconds

Co-authored-by: Andy Rudd <[email protected]>
Co-authored-by: Gladwin Johnson <[email protected]>
Co-authored-by: Neha Bhargava <[email protected]>
  • Loading branch information
4 people committed May 30, 2024
1 parent fa99d05 commit 239d9d6
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Microsoft.Identity.Client.Utils
Expand All @@ -14,11 +12,14 @@ namespace Microsoft.Identity.Client.Utils
/// </summary>
internal struct MeasureDurationResult<TResult>
{
private const int TicksPerMicrosecond = 10;
private static readonly double s_tickFrequency = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;

public MeasureDurationResult(TResult result, long ticks)
{
Result = result;
Milliseconds = ticks / TimeSpan.TicksPerMillisecond;
Microseconds = ticks / (TimeSpan.TicksPerMillisecond / 1000);
Milliseconds = (long)(ticks / s_tickFrequency / TimeSpan.TicksPerMillisecond);
Microseconds = (long)(ticks * s_tickFrequency / TicksPerMicrosecond % 1000);
Ticks = ticks;
}

Expand All @@ -45,10 +46,13 @@ public MeasureDurationResult(TResult result, long ticks)
/// </summary>
internal struct MeasureDurationResult
{
private const int TicksPerMicrosecond = 10;
private static readonly double s_tickFrequency = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;

public MeasureDurationResult(long ticks)
{
Milliseconds = ticks / TimeSpan.TicksPerMillisecond;
Microseconds = ticks / (TimeSpan.TicksPerMillisecond / 1000);
Milliseconds = (long)(ticks * s_tickFrequency / TimeSpan.TicksPerMillisecond % 1000);
Microseconds = (long)(ticks * s_tickFrequency / TicksPerMicrosecond % 1000);
Ticks = ticks;
}

Expand Down

0 comments on commit 239d9d6

Please sign in to comment.