-
Notifications
You must be signed in to change notification settings - Fork 453
Adding benchmark for new ValidateTokenAsync model vs old #2779
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4067f67
Adding benchmark for new ValidateTokenAsync model vs old.
ea1c1be
Update benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyn…
FuPingFranco a7d2680
Updated class naming to be more explicit and added benchmark using clone
ae495dd
Combine and categorize benchmarks into ValidateTokenAsyncTests
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
86 changes: 86 additions & 0 deletions
86
benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithVPTests.cs
This file contains hidden or 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,86 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Security.Claims; | ||
| using System.Threading.Tasks; | ||
| using BenchmarkDotNet.Attributes; | ||
| using Microsoft.IdentityModel.JsonWebTokens; | ||
| using Microsoft.IdentityModel.Tokens; | ||
|
|
||
| namespace Microsoft.IdentityModel.Benchmarks | ||
| { | ||
| // dotnet run -c release -f net8.0 --filter Microsoft.IdentityModel.Benchmarks.ValidateTokenAsyncWithVPTests* | ||
|
|
||
| public class ValidateTokenAsyncWithVPTests | ||
FuPingFranco marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| private CallContext _callContext; | ||
| private JsonWebTokenHandler _jsonWebTokenHandler; | ||
| private SecurityTokenDescriptor _tokenDescriptor; | ||
| private SecurityTokenDescriptor _tokenDescriptorExtendedClaims; | ||
| private string _jws; | ||
| private string _jwsExtendedClaims; | ||
| private TokenValidationParameters _tokenValidationParameters; //TODO:Add additional test to compare with ValidationParameters also use clone for perf. | ||
| private ValidationParameters _validationParameters; | ||
|
|
||
| [GlobalSetup] | ||
| public void Setup() | ||
| { | ||
| _tokenDescriptor = new SecurityTokenDescriptor | ||
| { | ||
| Claims = BenchmarkUtils.Claims, | ||
| SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256, | ||
| }; | ||
|
|
||
| _tokenDescriptorExtendedClaims = new SecurityTokenDescriptor | ||
| { | ||
| Claims = BenchmarkUtils.ClaimsExtendedExample, | ||
| SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256, | ||
| }; | ||
|
|
||
| _jsonWebTokenHandler = new JsonWebTokenHandler(); | ||
| _jws = _jsonWebTokenHandler.CreateToken(_tokenDescriptor); | ||
| _jwsExtendedClaims = _jsonWebTokenHandler.CreateToken(_tokenDescriptorExtendedClaims); | ||
|
|
||
| _validationParameters = new ValidationParameters(); | ||
| _validationParameters.ValidAudiences.Add(BenchmarkUtils.Audience); | ||
| _validationParameters.ValidIssuers.Add(BenchmarkUtils.Issuer); | ||
| _validationParameters.IssuerSigningKeys.Add(BenchmarkUtils.SigningCredentialsRsaSha256.Key); | ||
|
|
||
| _callContext = new CallContext(); | ||
|
|
||
| _tokenValidationParameters = new TokenValidationParameters() | ||
| { | ||
| ValidAudience = BenchmarkUtils.Audience, | ||
| ValidateLifetime = true, | ||
| ValidIssuer = BenchmarkUtils.Issuer, | ||
| IssuerSigningKey = BenchmarkUtils.SigningCredentialsRsaSha256.Key, | ||
| }; | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsyncWithVP_CreateClaims() | ||
| { | ||
| var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false); | ||
| var claimsIdentity = result.ClaimsIdentity; | ||
| var claims = claimsIdentity.Claims; | ||
| return claims.ToList(); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsync_CreateClaims() | ||
| { | ||
| var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false); | ||
| var claimsIdentity = result.ClaimsIdentity; | ||
| var claims = claimsIdentity.Claims; | ||
| return claims.ToList(); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsyncWithVP() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false); | ||
|
|
||
| [Benchmark] | ||
| public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsync() => await _jsonWebTokenHandler.ValidateTokenAsync(_jws, _tokenValidationParameters).ConfigureAwait(false); | ||
FuPingFranco marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.