Auios.Stopwatch
1.0.0
A stopwatch class designed towards measuring how much time a process or section of code uses. Great for measuring code efficiency and performance.
Install-Package Auios.Stopwatch -Version 1.0.0
dotnet add package Auios.Stopwatch --version 1.0.0
<PackageReference Include="Auios.Stopwatch" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Auios.Stopwatch --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Auios.Stopwatch
using System;
namespace Auios.Stopwatch
{
public class Stopwatch
{
private DateTime start;
private DateTime end;
private TimeSpan time = TimeSpan.Zero;
private TimeSpan highest = TimeSpan.Zero;
private bool isRunning;
public Stopwatch()
{
Reset();
}
public void Start()
{
if(!isRunning)
{
start = DateTime.Now;
isRunning = true;
}
}
public void Stop()
{
if (isRunning)
{
isRunning = false;
end = DateTime.Now;
time = end - start;
if (time > highest) highest = time;
}
}
public void Reset()
{
time = TimeSpan.Zero;
highest = TimeSpan.Zero;
isRunning = false;
}
// Time
public float Ms() => (float)time.TotalMilliseconds;
public float Seconds() => (float)time.TotalSeconds;
public float Minutes() => (float)time.TotalMinutes;
public long Ticks() => time.Ticks;
// Highest time
public float HighestMs() => (float)highest.TotalMilliseconds;
public float HighestSeconds() => (float)highest.TotalSeconds;
public float HighestMinutes() => (float)highest.TotalMinutes;
public long HighestTicks() => highest.Ticks;
}
}
Auios.Stopwatch
using System;
namespace Auios.Stopwatch
{
public class Stopwatch
{
private DateTime start;
private DateTime end;
private TimeSpan time = TimeSpan.Zero;
private TimeSpan highest = TimeSpan.Zero;
private bool isRunning;
public Stopwatch()
{
Reset();
}
public void Start()
{
if(!isRunning)
{
start = DateTime.Now;
isRunning = true;
}
}
public void Stop()
{
if (isRunning)
{
isRunning = false;
end = DateTime.Now;
time = end - start;
if (time > highest) highest = time;
}
}
public void Reset()
{
time = TimeSpan.Zero;
highest = TimeSpan.Zero;
isRunning = false;
}
// Time
public float Ms() => (float)time.TotalMilliseconds;
public float Seconds() => (float)time.TotalSeconds;
public float Minutes() => (float)time.TotalMinutes;
public long Ticks() => time.Ticks;
// Highest time
public float HighestMs() => (float)highest.TotalMilliseconds;
public float HighestSeconds() => (float)highest.TotalSeconds;
public float HighestMinutes() => (float)highest.TotalMinutes;
public long HighestTicks() => highest.Ticks;
}
}
Release Notes
1.0.0
* Base Stopwatch class
Dependencies
-
.NETCoreApp 3.1
- No dependencies.
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 84 | 10/31/2020 |