mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Diagnostics;
|
|
|
|
namespace Squidex.Infrastructure
|
|
{
|
|
public struct ValueStopwatch
|
|
{
|
|
private const long TicksPerMillisecond = 10000;
|
|
private const long TicksPerSecond = TicksPerMillisecond * 1000;
|
|
|
|
private static readonly double TickFrequency;
|
|
|
|
private readonly long startTime;
|
|
|
|
static ValueStopwatch()
|
|
{
|
|
if (Stopwatch.IsHighResolution)
|
|
{
|
|
TickFrequency = (double)TicksPerSecond / Stopwatch.Frequency;
|
|
}
|
|
}
|
|
|
|
public ValueStopwatch(long startTime)
|
|
{
|
|
this.startTime = startTime;
|
|
}
|
|
|
|
public static ValueStopwatch StartNew()
|
|
{
|
|
return new ValueStopwatch(Stopwatch.GetTimestamp());
|
|
}
|
|
|
|
public long Stop()
|
|
{
|
|
var elapsed = Stopwatch.GetTimestamp() - startTime;
|
|
|
|
if (elapsed < 0)
|
|
{
|
|
return elapsed;
|
|
}
|
|
|
|
if (Stopwatch.IsHighResolution)
|
|
{
|
|
elapsed = unchecked((long)(elapsed * TickFrequency));
|
|
}
|
|
|
|
return elapsed / TicksPerMillisecond;
|
|
}
|
|
}
|
|
}
|
|
|