mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 14:08:25 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
1 changed files with 768360 additions and 0 deletions
42
brutal.concurrency/Brutal.Concurrency/Jobs/JobRunnerTimer.cs
Normal file
42
brutal.concurrency/Brutal.Concurrency/Jobs/JobRunnerTimer.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System.Diagnostics;
|
||||
using Brutal.Concurrency.Statistics;
|
||||
|
||||
namespace Brutal.Concurrency.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// A class that can take a series of time measurements and record return some basic stats.
|
||||
/// </summary>
|
||||
internal class JobRunnerTimer
|
||||
{
|
||||
public void Start()
|
||||
{
|
||||
_workerStopwatch.Restart();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_workerStopwatch.Stop();
|
||||
AddSample(_workerStopwatch.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
|
||||
public void ResetTimings()
|
||||
{
|
||||
_sampler.Reset();
|
||||
}
|
||||
|
||||
public double AverageMillis => _sampler.Average;
|
||||
public double MaxMillis => _sampler.Max;
|
||||
public double LastMillis => _sampler.Last;
|
||||
|
||||
#region Private
|
||||
|
||||
private void AddSample(double milliSeconds)
|
||||
{
|
||||
_sampler.Add(milliSeconds);
|
||||
}
|
||||
|
||||
private readonly Stopwatch _workerStopwatch = new();
|
||||
private readonly Sampler<double> _sampler = new();
|
||||
|
||||
#endregion
|
||||
}
|
||||
Loading…
Reference in a new issue