Whojoo.PerformanceCounter
1.4.0
dotnet add package Whojoo.PerformanceCounter --version 1.4.0
NuGet\Install-Package Whojoo.PerformanceCounter -Version 1.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Whojoo.PerformanceCounter" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Whojoo.PerformanceCounter" Version="1.4.0" />
<PackageReference Include="Whojoo.PerformanceCounter" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Whojoo.PerformanceCounter --version 1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Whojoo.PerformanceCounter, 1.4.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Whojoo.PerformanceCounter@1.4.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Whojoo.PerformanceCounter&version=1.4.0
#tool nuget:?package=Whojoo.PerformanceCounter&version=1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PerformanceCounter
Simple .NET tool for recording and reporting performance for multipe steps
Installation
Install the PerformanceCounter NuGet Package
.NET CLI
dotnet add package Whojoo.PerformanceCounter
Usage
An example usage could be like the following, taking from one of the samples:
app.MapGet("/test", async (ILogger<Program> logger) =>
{
// Create the counter, this automatically starts the counter and will log to Information
var performanceCounter = PerformanceCounterFactory.Start(logger);
// Record without returning a result
performanceCounter.RecordStep("SyncRecordNoResult", () =>
{
foreach (var step in Enumerable.Range(1, 1_000_000))
{
var foo = int.MaxValue - step;
}
});
// Record and take the result which could be used at a later step if required
var recordSyncResult = performanceCounter.RecordStep("SyncRecordWithResult", () =>
{
var returnResult = int.MaxValue;
foreach (var step in Enumerable.Range(1, 1_000_000))
{
returnResult -= step;
}
return returnResult;
});
// Supports async methods as well
await performanceCounter.RecordStepAsync("AsyncRecordNoResult", async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(500));
});
var recordAsyncResult = await performanceCounter.RecordStepAsync(
"AsyncRecordWithResult",
async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(500));
return 500;
});
// Report() to report all the performance details in a single structure log message.
performanceCounter.Report();
return recordAsyncResult + recordSyncResult;
});
This produces the following result in the Console:
info: Program[0]
Reporting performance counter PerformanceTest
- Step SyncRecordNoResult: 8.8065 ms
- Step SyncRecordWithResult: 5.4439 ms
- Step AsyncRecordNoResult: 500.6646 ms
- Step AsyncRecordWithResult: 501.8499 ms
- Total elapsed: 1016,7649 ms
And the following structured logging:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.Extensions.Logging (>= 9.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.