-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding P50, P90 and P100 percentiles to benchmarks #2411
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
benchmark/Microsoft.IdentityModel.Benchmarks/AntiVirusFriendlyConfig.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 |
---|---|---|
@@ -1,18 +1,121 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet.Columns; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Toolchains.InProcess.Emit; | ||
using BenchmarkDotNet.Reports; | ||
using BenchmarkDotNet.Running; | ||
|
||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
// Define custom columns for P50 and P99 latency | ||
public class P50Column : IColumn | ||
{ | ||
public string Id => nameof(P50Column); | ||
public string ColumnName => "P50"; | ||
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false; | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase) => GetValue(summary, benchmarkCase, SummaryStyle.Default); | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style) | ||
{ | ||
// Get the statistics for the current benchmark | ||
var statistics = summary[benchmarkCase].ResultStatistics; | ||
// Calculate the P50 latency using the Percentile method | ||
var p50 = statistics.Percentiles.P50 / style.TimeUnit.NanosecondAmount; | ||
// Format the value using the style | ||
return p50.ToString($"F2") + $" {style.TimeUnit.Name}"; | ||
} | ||
public bool IsAvailable(Summary summary) => true; | ||
public bool AlwaysShow => true; | ||
public ColumnCategory Category => ColumnCategory.Statistics; | ||
public int PriorityInCategory => 0; | ||
public bool IsNumeric => true; | ||
public UnitType UnitType => UnitType.Time; | ||
public string Legend => "50th percentile of latency"; | ||
} | ||
|
||
public class P95Column : IColumn | ||
{ | ||
public string Id => nameof(P99Column); | ||
public string ColumnName => "P95"; | ||
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false; | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase) => GetValue(summary, benchmarkCase, SummaryStyle.Default); | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style) | ||
{ | ||
// Get the statistics for the current benchmark | ||
var statistics = summary[benchmarkCase].ResultStatistics; | ||
// Calculate the P99 latency using the Percentile method | ||
var p95 = statistics.Percentiles.P95 / style.TimeUnit.NanosecondAmount; | ||
// Format the value using the style | ||
return p95.ToString($"F2") + $" {style.TimeUnit.Name}"; | ||
} | ||
public bool IsAvailable(Summary summary) => true; | ||
public bool AlwaysShow => true; | ||
public ColumnCategory Category => ColumnCategory.Statistics; | ||
public int PriorityInCategory => 0; | ||
public bool IsNumeric => true; | ||
public UnitType UnitType => UnitType.Time; | ||
public string Legend => "95th percentile of latency"; | ||
} | ||
|
||
public class P99Column : IColumn | ||
{ | ||
public string Id => nameof(P99Column); | ||
public string ColumnName => "P99"; | ||
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false; | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase) => GetValue(summary, benchmarkCase, SummaryStyle.Default); | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style) | ||
{ | ||
// Get the statistics for the current benchmark | ||
var statistics = summary[benchmarkCase].ResultStatistics; | ||
// Calculate the P99 latency using the Percentile method | ||
var p99 = statistics.Percentiles.P90 / style.TimeUnit.NanosecondAmount; | ||
// Format the value using the style | ||
return p99.ToString($"F2") + $" {style.TimeUnit.Name}"; | ||
} | ||
public bool IsAvailable(Summary summary) => true; | ||
public bool AlwaysShow => true; | ||
public ColumnCategory Category => ColumnCategory.Statistics; | ||
public int PriorityInCategory => 0; | ||
public bool IsNumeric => true; | ||
public UnitType UnitType => UnitType.Time; | ||
public string Legend => "99th percentile of latency"; | ||
} | ||
|
||
public class P100Column : IColumn | ||
{ | ||
public string Id => nameof(P100Column); | ||
public string ColumnName => "P100"; | ||
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false; | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase) => GetValue(summary, benchmarkCase, SummaryStyle.Default); | ||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style) | ||
{ | ||
// Get the statistics for the current benchmark | ||
var statistics = summary[benchmarkCase].ResultStatistics; | ||
// Calculate the P99 latency using the Percentile method | ||
var p100 = statistics.Percentiles.P100 / style.TimeUnit.NanosecondAmount; | ||
// Format the value using the style | ||
return p100.ToString($"F2")+ $" {style.TimeUnit.Name}"; | ||
} | ||
public bool IsAvailable(Summary summary) => true; | ||
public bool AlwaysShow => true; | ||
public ColumnCategory Category => ColumnCategory.Statistics; | ||
public int PriorityInCategory => 0; | ||
public bool IsNumeric => true; | ||
public UnitType UnitType => UnitType.Time; | ||
public string Legend => "100th percentile of latency"; | ||
} | ||
|
||
|
||
public class AntiVirusFriendlyConfig : ManualConfig | ||
{ | ||
public AntiVirusFriendlyConfig() | ||
{ | ||
AddJob(Job.MediumRun | ||
.WithToolchain(InProcessEmitToolchain.Instance)); | ||
AddColumn(new P50Column(), new P95Column(), new P99Column(), new P100Column()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://benchmarkdotnet.org/articles/features/statistics.html
Most of these look like they already exist in StatisticColumn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. The columns explicitly get the ones we want and not the others