-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new benchmarks, ignore local outputs, fix crank config * Fix private members, combine solutions
- Loading branch information
Showing
11 changed files
with
262 additions
and
24 deletions.
There are no files selected for viewing
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
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
42 changes: 42 additions & 0 deletions
42
benchmark/Microsoft.IdentityModel.Benchmarks/CreateJWETests.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Security.Claims; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Microsoft.IdentityModel.TestUtils; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
[Config(typeof(AntiVirusFriendlyConfig))] | ||
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")] | ||
[MemoryDiagnoser] | ||
public class CreateJWETests | ||
{ | ||
private JsonWebTokenHandler _jsonWebTokenHandler; | ||
private JwtSecurityTokenHandler _jwtSecurityTokenHandler; | ||
private SecurityTokenDescriptor _tokenDescriptor; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_jsonWebTokenHandler = new JsonWebTokenHandler(); | ||
_jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); | ||
_tokenDescriptor = new SecurityTokenDescriptor | ||
{ | ||
SigningCredentials = KeyingMaterial.JsonWebKeyRsa256SigningCredentials, | ||
EncryptingCredentials = KeyingMaterial.DefaultSymmetricEncryptingCreds_Aes256_Sha512_512, | ||
Subject = new ClaimsIdentity(Default.PayloadClaims), | ||
TokenType = "TokenType" | ||
}; | ||
} | ||
|
||
[Benchmark] | ||
public string JsonWebTokenHandler_CreateJWE() => _jsonWebTokenHandler.CreateToken(_tokenDescriptor); | ||
|
||
[Benchmark] | ||
public string JwtSecurityTokenHandler_CreateJWE() => _jwtSecurityTokenHandler.CreateEncodedJwt(_tokenDescriptor); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
benchmark/Microsoft.IdentityModel.Benchmarks/CreateSignedHttpRequestTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.IdentityModel.Protocols.SignedHttpRequest; | ||
using Microsoft.IdentityModel.Protocols.SignedHttpRequest.Tests; | ||
using Microsoft.IdentityModel.Protocols; | ||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")] | ||
[MemoryDiagnoser] | ||
public class CreateSignedHttpRequestTests | ||
{ | ||
private SignedHttpRequestHandler _signedHttpRequestHandler; | ||
private SignedHttpRequestDescriptor _signedHttpRequestDescriptor; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_signedHttpRequestHandler = new SignedHttpRequestHandler(); | ||
_signedHttpRequestDescriptor = new SignedHttpRequestDescriptor( | ||
SignedHttpRequestTestUtils.DefaultEncodedAccessToken, | ||
new HttpRequestData(), | ||
SignedHttpRequestTestUtils.DefaultSigningCredentials, | ||
new SignedHttpRequestCreationParameters() | ||
{ | ||
CreateM = false, | ||
CreateP = false, | ||
CreateU = false | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public string SHRHandler_CreateSignedHttpRequest() => _signedHttpRequestHandler.CreateSignedHttpRequest(_signedHttpRequestDescriptor); | ||
|
||
} | ||
} |
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
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
55 changes: 55 additions & 0 deletions
55
benchmark/Microsoft.IdentityModel.Benchmarks/ValidateJWEAsyncTests.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Microsoft.IdentityModel.TestUtils; | ||
using Microsoft.IdentityModel.Tokens; | ||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
[Config(typeof(AntiVirusFriendlyConfig))] | ||
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")] | ||
[MemoryDiagnoser] | ||
public class ValidateJWEAsyncTests | ||
{ | ||
private JsonWebTokenHandler _jsonWebTokenHandler; | ||
private JwtSecurityTokenHandler _jwtSecurityTokenHandler; | ||
private SecurityTokenDescriptor _tokenDescriptor; | ||
private string _jweFromJsonHandler; | ||
private string _jweFromJwtHandler; | ||
private TokenValidationParameters _validationParameters; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_jsonWebTokenHandler = new JsonWebTokenHandler(); | ||
_jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); | ||
_tokenDescriptor = new SecurityTokenDescriptor | ||
{ | ||
SigningCredentials = KeyingMaterial.JsonWebKeyRsa256SigningCredentials, | ||
EncryptingCredentials = KeyingMaterial.DefaultSymmetricEncryptingCreds_Aes256_Sha512_512, | ||
Subject = new ClaimsIdentity(Default.PayloadClaims), | ||
TokenType = "TokenType" | ||
}; | ||
_jweFromJsonHandler = _jsonWebTokenHandler.CreateToken(_tokenDescriptor); | ||
_jweFromJwtHandler = _jwtSecurityTokenHandler.CreateEncodedJwt(_tokenDescriptor); | ||
_validationParameters = new TokenValidationParameters | ||
{ | ||
IssuerSigningKey = KeyingMaterial.JsonWebKeyRsa256SigningCredentials.Key, | ||
TokenDecryptionKey = KeyingMaterial.DefaultSymmetricSecurityKey_512, | ||
ValidAudience = Default.Audience, | ||
ValidIssuer = Default.Issuer | ||
}; | ||
} | ||
|
||
[Benchmark] | ||
public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateJWEAsync() => await _jsonWebTokenHandler.ValidateTokenAsync(_jweFromJsonHandler, _validationParameters); | ||
|
||
[Benchmark] | ||
public ClaimsPrincipal JwtSecurityTokenHandler_ValidateJWEAsync() => _jwtSecurityTokenHandler.ValidateToken(_jweFromJwtHandler, _validationParameters, out _); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
benchmark/Microsoft.IdentityModel.Benchmarks/ValidateSignedHttpRequestAsyncTests.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.IdentityModel.Protocols.SignedHttpRequest.Tests; | ||
using Microsoft.IdentityModel.Protocols.SignedHttpRequest; | ||
using Microsoft.IdentityModel.Protocols; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")] | ||
[MemoryDiagnoser] | ||
public class ValidateSignedHttpRequestAsyncTests | ||
{ | ||
private SignedHttpRequestHandler _signedHttpRequestHandler; | ||
private SignedHttpRequestDescriptor _signedHttpRequestDescriptor; | ||
private SignedHttpRequestValidationContext _validationContext; | ||
private string _signedHttpRequest; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var requestData = new HttpRequestData(); | ||
_signedHttpRequestHandler = new SignedHttpRequestHandler(); | ||
_signedHttpRequestDescriptor = new SignedHttpRequestDescriptor( | ||
SignedHttpRequestTestUtils.DefaultEncodedAccessToken, | ||
requestData, | ||
SignedHttpRequestTestUtils.DefaultSigningCredentials, | ||
new SignedHttpRequestCreationParameters() | ||
{ | ||
CreateM = false, | ||
CreateP = false, | ||
CreateU = false | ||
}); | ||
_signedHttpRequest = _signedHttpRequestHandler.CreateSignedHttpRequest(_signedHttpRequestDescriptor); | ||
_validationContext = new SignedHttpRequestValidationContext( | ||
_signedHttpRequest, | ||
requestData, | ||
SignedHttpRequestTestUtils.DefaultTokenValidationParameters); | ||
} | ||
|
||
[Benchmark] | ||
public async Task<SignedHttpRequestValidationResult> SHRHandler_ValidateSignedHttpRequestAsync() => await _signedHttpRequestHandler.ValidateSignedHttpRequestAsync(_validationContext, CancellationToken.None); | ||
} | ||
} |
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
Oops, something went wrong.