diff --git a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncBatcher.cs b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncBatcher.cs index 1776abe926..ebfb7d87ff 100644 --- a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncBatcher.cs +++ b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncBatcher.cs @@ -164,7 +164,7 @@ private async Task DispatchHelperAsync( try { - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); PartitionKeyRangeBatchExecutionResult result = await this.executor(serverRequest, trace, cancellationToken); diff --git a/Microsoft.Azure.Cosmos/src/Metrics.cs b/Microsoft.Azure.Cosmos/src/Metrics.cs index 6c98bea60f..b61b6b578b 100644 --- a/Microsoft.Azure.Cosmos/src/Metrics.cs +++ b/Microsoft.Azure.Cosmos/src/Metrics.cs @@ -6,14 +6,15 @@ namespace Microsoft.Azure.Cosmos { using System.Diagnostics; using System.Globalization; + using Microsoft.Azure.Documents; internal sealed class Metrics { - private readonly Stopwatch stopwatch; + private ValueStopwatch stopwatch; public Metrics() { - this.stopwatch = new Stopwatch(); + this.stopwatch = new ValueStopwatch(); } public int Count diff --git a/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/HistogramExtensions.cs b/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/HistogramExtensions.cs index 2c37aa4fb5..ca9d19431e 100644 --- a/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/HistogramExtensions.cs +++ b/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/HistogramExtensions.cs @@ -23,6 +23,7 @@ using System.Linq; using HdrHistogram.Iteration; using HdrHistogram.Output; +using Microsoft.Azure.Documents; namespace HdrHistogram { @@ -211,9 +212,9 @@ public static void OutputPercentileDistribution(this HistogramBase histogram, /// public static void Record(this IRecorder recorder, Action action) { - var start = Stopwatch.GetTimestamp(); + var start = ValueStopwatch.GetTimestamp(); action(); - var elapsed = Stopwatch.GetTimestamp() - start; + var elapsed = ValueStopwatch.GetTimestamp() - start; recorder.RecordValue(elapsed); } @@ -251,12 +252,12 @@ private sealed class Timer : IDisposable public Timer(IRecorder recorder) { _recorder = recorder; - _start = Stopwatch.GetTimestamp(); + _start = ValueStopwatch.GetTimestamp(); } public void Dispose() { - var elapsed = Stopwatch.GetTimestamp() - _start; + var elapsed = ValueStopwatch.GetTimestamp() - _start; _recorder.RecordValue(elapsed); } } diff --git a/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/OutputScalingFactor.cs b/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/OutputScalingFactor.cs index 7bb89f4e0e..3d5f450595 100644 --- a/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/OutputScalingFactor.cs +++ b/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/OutputScalingFactor.cs @@ -17,6 +17,7 @@ */ using System.Diagnostics; +using Microsoft.Azure.Documents; namespace HdrHistogram { @@ -33,16 +34,16 @@ internal static class OutputScalingFactor /// /// For use when values are recorded with and output should be reported in microseconds. /// - public static readonly double TimeStampToMicroseconds = Stopwatch.Frequency / (1000d * 1000d); + public static readonly double TimeStampToMicroseconds = ValueStopwatch.Frequency / (1000d * 1000d); /// /// For use when values are recorded with and output should be reported in milliseconds. /// - public static readonly double TimeStampToMilliseconds = Stopwatch.Frequency / 1000d; + public static readonly double TimeStampToMilliseconds = ValueStopwatch.Frequency / 1000d; /// /// For use when values are recorded with and output should be reported in seconds. /// - public static readonly double TimeStampToSeconds = Stopwatch.Frequency; + public static readonly double TimeStampToSeconds = ValueStopwatch.Frequency; } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/TimeStamp.cs b/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/TimeStamp.cs index dc16b93d15..58addd119e 100644 --- a/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/TimeStamp.cs +++ b/Microsoft.Azure.Cosmos/src/OSS/HdrHistogram/TimeStamp.cs @@ -9,6 +9,7 @@ // using System.Diagnostics; +using Microsoft.Azure.Documents; namespace HdrHistogram { @@ -24,7 +25,7 @@ internal static class TimeStamp /// The number of system timer ticks that represent the . public static long Seconds(long seconds) { - return Stopwatch.Frequency * seconds; + return ValueStopwatch.Frequency * seconds; } /// diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/FetchExecutionRangeAccumulator.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/FetchExecutionRangeAccumulator.cs index 28bc7b2062..cf71516eda 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/FetchExecutionRangeAccumulator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/FetchExecutionRangeAccumulator.cs @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics using System; using System.Collections.Generic; using System.Diagnostics; + using Microsoft.Azure.Documents; /// /// Accumulator that acts as a builder of FetchExecutionRanges @@ -20,7 +21,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics sealed class FetchExecutionRangeAccumulator { private readonly DateTime constructionTime; - private readonly Stopwatch stopwatch; + private ValueStopwatch stopwatch; private List fetchExecutionRanges; private DateTime startTime; private DateTime endTime; @@ -33,7 +34,7 @@ public FetchExecutionRangeAccumulator() { this.constructionTime = DateTime.UtcNow; // This stopwatch is always running and is only used to calculate deltas that are synchronized with the construction time. - this.stopwatch = Stopwatch.StartNew(); + this.stopwatch = ValueStopwatch.StartNew(); this.fetchExecutionRanges = new List(); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/SchedulingStopwatch.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/SchedulingStopwatch.cs index 632b7c32c4..0b4ca878c8 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/SchedulingStopwatch.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/SchedulingStopwatch.cs @@ -4,6 +4,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics { using System.Diagnostics; + using Microsoft.Azure.Documents; /// /// This class keeps track of scheduling metrics for a single process using a stopwatch interface. @@ -16,17 +17,17 @@ internal sealed class SchedulingStopwatch /// /// Stopwatch used to measure turnaround time. /// - private readonly Stopwatch turnaroundTimeStopwatch; + private ValueStopwatch turnaroundTimeStopwatch; /// /// Stopwatch used to measure response time. /// - private readonly Stopwatch responseTimeStopwatch; + private ValueStopwatch responseTimeStopwatch; /// /// Stopwatch used to measure runtime. /// - private readonly Stopwatch runTimeStopwatch; + private ValueStopwatch runTimeStopwatch; /// /// Number of times the process was preempted. @@ -43,9 +44,9 @@ internal sealed class SchedulingStopwatch /// public SchedulingStopwatch() { - this.turnaroundTimeStopwatch = new Stopwatch(); - this.responseTimeStopwatch = new Stopwatch(); - this.runTimeStopwatch = new Stopwatch(); + this.turnaroundTimeStopwatch = new ValueStopwatch(); + this.responseTimeStopwatch = new ValueStopwatch(); + this.runTimeStopwatch = new ValueStopwatch(); } /// diff --git a/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs b/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs index 176f2ebc1b..2bb61740f3 100644 --- a/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs +++ b/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs @@ -10,14 +10,15 @@ namespace Microsoft.Azure.Cosmos.Tracing using System.Linq; using System.Runtime.CompilerServices; using Microsoft.Azure.Cosmos.Tracing.TraceData; + using Microsoft.Azure.Documents; internal sealed class Trace : ITrace { private static readonly IReadOnlyDictionary EmptyDictionary = new Dictionary(); private readonly List children; private readonly Lazy> data; - private readonly Stopwatch stopwatch; private readonly ISet<(string, Uri)> regionContactedInternal; + private ValueStopwatch stopwatch; private Trace( string name, @@ -29,7 +30,7 @@ private Trace( this.Name = name ?? throw new ArgumentNullException(nameof(name)); this.Id = Guid.NewGuid(); this.StartTime = DateTime.UtcNow; - this.stopwatch = Stopwatch.StartNew(); + this.stopwatch = ValueStopwatch.StartNew(); this.Level = level; this.Component = component; this.Parent = parent; diff --git a/Microsoft.Azure.Cosmos/src/WebExceptionRetryPolicy.cs b/Microsoft.Azure.Cosmos/src/WebExceptionRetryPolicy.cs index e11ad09642..be02f3391f 100644 --- a/Microsoft.Azure.Cosmos/src/WebExceptionRetryPolicy.cs +++ b/Microsoft.Azure.Cosmos/src/WebExceptionRetryPolicy.cs @@ -18,7 +18,7 @@ internal sealed class WebExceptionRetryPolicy : IRetryPolicy private const int initialBackoffSeconds = 1; private const int backoffMultiplier = 2; - private Stopwatch durationTimer = new Stopwatch(); + private ValueStopwatch durationTimer = new ValueStopwatch(); private int attemptCount = 1; // Don't penalise first retry with delay. diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTests.cs index eeb74443e2..06d9e80b86 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTests.cs @@ -771,7 +771,7 @@ private async Task WaitAndAssert( // As this feature is thread based execution so wait for the results to avoid test flakiness List localCopyOfActualInfo = null; - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); do { await Task.Delay(TimeSpan.FromMilliseconds(1500)); // wait at least for 1 round of telemetry diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTests.cs index 6eba048998..6df09dd807 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTests.cs @@ -132,8 +132,8 @@ public async Task InitTaskThreadSafe() { tasks.Add(this.ReadNotFound(container)); } - - Stopwatch sw = Stopwatch.StartNew(); + + ValueStopwatch sw = ValueStopwatch.StartNew(); while(this.TaskStartedCount < 10 && sw.Elapsed.TotalSeconds < 2) { await Task.Delay(TimeSpan.FromMilliseconds(50)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/PartitionKeyRangeCacheTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/PartitionKeyRangeCacheTests.cs index 74d420cbdc..504f06467f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/PartitionKeyRangeCacheTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/PartitionKeyRangeCacheTests.cs @@ -85,7 +85,7 @@ public async Task VerifyPkRangeCacheRefreshOnSplitWithErrorsAsync() Task backgroundItemOperatios = Task.Factory.StartNew(() => this.CreateAndReadItemBackgroundLoop(container, exceptions)); // Wait for the background job to start - Stopwatch stopwatch = Stopwatch.StartNew(); + Documents.ValueStopwatch stopwatch = Documents.ValueStopwatch.StartNew(); while (!this.loopBackgroundOperaitons && stopwatch.Elapsed.TotalSeconds < 30) { await Task.Delay(TimeSpan.FromSeconds(.5)); @@ -96,7 +96,7 @@ public async Task VerifyPkRangeCacheRefreshOnSplitWithErrorsAsync() // Cause direct call to hit a split exception and wait for the background job to hit it causeSplitExceptionInRntbdCall = true; - stopwatch = Stopwatch.StartNew(); + stopwatch = Documents.ValueStopwatch.StartNew(); while (causeSplitExceptionInRntbdCall && stopwatch.Elapsed.TotalSeconds < 10) { await Task.Delay(TimeSpan.FromSeconds(.5)); @@ -106,7 +106,7 @@ public async Task VerifyPkRangeCacheRefreshOnSplitWithErrorsAsync() // Cause another direct call split exception causeSplitExceptionInRntbdCall = true; - stopwatch = Stopwatch.StartNew(); + stopwatch = Documents.ValueStopwatch.StartNew(); while (causeSplitExceptionInRntbdCall && stopwatch.Elapsed.TotalSeconds < 10) { await Task.Delay(TimeSpan.FromSeconds(.5)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs index 67d837c52d..c18ac5e420 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryPerfTest/ContentSerializationPerformanceTests.cs @@ -112,8 +112,8 @@ private async Task RunQueryAsync(Container container) private async Task GetIteratorResponse(FeedIterator feedIterator) { MetricsAccumulator metricsAccumulator = new MetricsAccumulator(); - Stopwatch totalTime = new Stopwatch(); - Stopwatch getTraceTime = new Stopwatch(); + Documents.ValueStopwatch totalTime = new Documents.ValueStopwatch(); + Documents.ValueStopwatch getTraceTime = new Documents.ValueStopwatch(); string diagnosticDataPath = Path.GetFullPath(DiagnosticsDataFileName); while (feedIterator.HasMoreResults) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/StopwatchAllocationsBenchmark.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/StopwatchAllocationsBenchmark.cs new file mode 100644 index 0000000000..334fc74ecf --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/StopwatchAllocationsBenchmark.cs @@ -0,0 +1,50 @@ +namespace Microsoft.Azure.Cosmos.Benchmarks +{ + using System; + using BenchmarkDotNet.Attributes; + using Microsoft.Azure.Documents; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + using System.Diagnostics; + + [MemoryDiagnoser] + + public class StopwatchAllocationsBenchmark + { + [Benchmark] + public void StopwatchAllocation() + { + _ = new Stopwatch(); + } + + [Benchmark] + public void ValueStopwatchAllocation() + { + _ = new ValueStopwatch(); + } + + [Benchmark] + public void StopwatchAsField() + { + _ = new StopwatchHolder(); + } + + [Benchmark] + public void ValueStopwatchBoxedAsField() + { + _ = new ValueStopwatchHolder(); + } + + private class StopwatchHolder + { + private readonly Stopwatch stopwatch = new Stopwatch(); + } + + private class ValueStopwatchHolder + { + private readonly ValueStopwatch stopwatch = new ValueStopwatch(); + } + } +} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs index f1f62959a2..6d5db62d6d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/Metrics/Performance.cs @@ -8,6 +8,7 @@ namespace Microsoft.Azure.Cosmos.Performance.Tests.Query.Metrics using Microsoft.Azure.Cosmos.Query.Core.Metrics; using System.Diagnostics; using BenchmarkDotNet.Attributes; + using Microsoft.Azure.Documents; public class Performance { @@ -33,7 +34,7 @@ public class Performance [Benchmark] public void TestParse() { - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); for (int i = 0; i < 100000; i++) { BackendMetricsParser.TryParse(delimitedString, out BackendMetrics backendMetrics); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AsyncCacheTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AsyncCacheTest.cs index 80357c9ad0..586da4f4f3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AsyncCacheTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AsyncCacheTest.cs @@ -12,6 +12,7 @@ namespace Microsoft.Azure.Cosmos.Tests using System.Threading.Tasks; using Microsoft.Azure.Cosmos.Common; using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.Azure.Documents; [TestClass] public class AsyncCacheTest @@ -298,7 +299,7 @@ public async Task TestFailureOnOneThreadDoesNotFailAnother() public async Task TestAsyncDeadlock() { AsyncCache cache = new AsyncCache(); - Stopwatch stopwatch = new Stopwatch(); + ValueStopwatch stopwatch = new ValueStopwatch(); stopwatch.Start(); await Task.Factory.StartNew(() => diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosAuthorizationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosAuthorizationTests.cs index 7642673666..ea65c91d3c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosAuthorizationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosAuthorizationTests.cs @@ -372,7 +372,7 @@ public async Task TestTokenCredentialFailedToRefreshAsync() // Token refreshes fails except for the first time, but the cached token will be served as long as it is valid. // Wait for the background refresh to occur. It should fail but the cached token should still be valid - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); while (testTokenCredential.NumTimesInvoked != 3) { Assert.IsTrue(stopwatch.Elapsed.TotalSeconds < 10, "The background task did not start in 10 seconds"); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GlobalEndpointManagerTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GlobalEndpointManagerTest.cs index 91eb61b733..28e24d7e55 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GlobalEndpointManagerTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GlobalEndpointManagerTest.cs @@ -15,6 +15,7 @@ namespace Microsoft.Azure.Cosmos using Microsoft.Azure.Cosmos.Routing; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; + using Microsoft.Azure.Documents; /// /// Tests for @@ -320,7 +321,7 @@ public async Task GetDatabaseAccountFromAnyLocationsMockTestAsync() slowPrimaryRegionHelper.ShouldDelayRequest = (uri) => uri == defaultEndpoint || uri == new Uri(databaseAccount.ReadLocationsInternal.First().Endpoint); slowPrimaryRegionHelper.ShouldFailRequest = slowPrimaryRegionHelper.ShouldDelayRequest; - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); globalEndpointResult = await GlobalEndpointManager.GetDatabaseAccountFromAnyLocationsAsync( defaultEndpoint: defaultEndpoint, locations: new List(){ @@ -548,7 +549,7 @@ void TraceHandler(string message) DefaultTrace.TraceSource.Listeners.Add(new TestTraceListener { Callback = TraceHandler }); DefaultTrace.InitEventListener(); - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); // Wait for the trace message saying the background refresh occurred while (!isGlobalEndpointRefreshStarted) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/AsyncCacheNonBlockingTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/AsyncCacheNonBlockingTests.cs index 1b9796d019..d5250b0408 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/AsyncCacheNonBlockingTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/AsyncCacheNonBlockingTests.cs @@ -193,7 +193,7 @@ public async Task ValidateAsyncCacheNonBlocking() }, forceRefresh: (_) => true); - Stopwatch concurrentOperationStopwatch = Stopwatch.StartNew(); + ValueStopwatch concurrentOperationStopwatch = ValueStopwatch.StartNew(); string concurrentUpdateTask = await asyncCache.GetAsync( "test", (_) => throw new Exception("should not refresh"), diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/TimerWheel/TimerWheelCoreTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/TimerWheel/TimerWheelCoreTests.cs index 18b5dbd69a..0c724b530d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/TimerWheel/TimerWheelCoreTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/TimerWheel/TimerWheelCoreTests.cs @@ -10,6 +10,7 @@ namespace Microsoft.Azure.Cosmos.Tests using System.Threading.Tasks; using Microsoft.Azure.Cosmos.Timers; using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.Azure.Documents; [TestClass] public class TimerWheelCoreTests @@ -109,7 +110,7 @@ public async Task TimeoutFires() const int resolution = 500; using TimerWheelCore wheel = new TimerWheelCore(TimeSpan.FromMilliseconds(resolution), 10); // 10 buckets of 500 ms go up to 5000ms TimerWheelTimer timer = wheel.CreateTimer(TimeSpan.FromMilliseconds(timerTimeout)); - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); await timer.StartTimerAsync(); stopwatch.Stop(); } @@ -123,7 +124,7 @@ public async Task TimeoutFires_SameTimeout() using TimerWheelCore wheel = new TimerWheelCore(TimeSpan.FromMilliseconds(resolution), 10); // 10 buckets of 500 ms go up to 5000ms TimerWheelTimer timer = wheel.CreateTimer(TimeSpan.FromMilliseconds(timerTimeout)); TimerWheelTimer timer2 = wheel.CreateTimer(TimeSpan.FromMilliseconds(timerTimeout)); - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); await Task.WhenAll(timer.StartTimerAsync(), timer2.StartTimerAsync()); stopwatch.Stop(); } @@ -142,7 +143,7 @@ public async Task MultipleTimeouts() int estimatedTimeout = (i + 1) * timerTimeout; TimerWheelTimer timer = wheel.CreateTimer(TimeSpan.FromMilliseconds(estimatedTimeout)); tasks.Add(Task.Run(async () => { - Stopwatch stopwatch = Stopwatch.StartNew(); + ValueStopwatch stopwatch = ValueStopwatch.StartNew(); await timer.StartTimerAsync(); stopwatch.Stop(); return (estimatedTimeout,stopwatch.ElapsedMilliseconds);