-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace PooledStopwatch with SharedStopwatch
- Loading branch information
Showing
5 changed files
with
73 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Compilers/Core/Portable/InternalUtilities/SharedStopwatch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Roslyn.Utilities | ||
{ | ||
internal struct SharedStopwatch | ||
{ | ||
private static readonly Stopwatch s_stopwatch = Stopwatch.StartNew(); | ||
|
||
private TimeSpan _accumulated; | ||
private TimeSpan _started; | ||
|
||
public readonly TimeSpan Elapsed | ||
{ | ||
get | ||
{ | ||
if (IsRunning) | ||
return _accumulated + s_stopwatch.Elapsed - _started; | ||
|
||
return _accumulated; | ||
} | ||
} | ||
|
||
public readonly long ElapsedMilliseconds => (long)Elapsed.TotalMilliseconds; | ||
public readonly bool IsRunning => _started != TimeSpan.Zero; | ||
|
||
public static SharedStopwatch StartNew() | ||
{ | ||
var result = new SharedStopwatch(); | ||
result.Start(); | ||
return result; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
Stop(); | ||
_accumulated = TimeSpan.Zero; | ||
} | ||
|
||
public void Restart() | ||
{ | ||
Reset(); | ||
Start(); | ||
} | ||
|
||
public void Start() | ||
{ | ||
if (!IsRunning) | ||
{ | ||
_started = s_stopwatch.Elapsed; | ||
} | ||
} | ||
|
||
public void Stop() | ||
{ | ||
if (IsRunning) | ||
{ | ||
_accumulated += s_stopwatch.Elapsed - _started; | ||
_started = TimeSpan.Zero; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters