diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-02 21:37:34 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-02 21:37:34 -0700 |
commit | bcdd8eb12670332b0de69752d583cba710490e38 (patch) | |
tree | 74b83b186088e742db82958ace7e4cc38c81689c /src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs | |
parent | 6c751fc1364d94733e099c3a21623033c85ad86d (diff) | |
download | DotNetOpenAuth-bcdd8eb12670332b0de69752d583cba710490e38.zip DotNetOpenAuth-bcdd8eb12670332b0de69752d583cba710490e38.tar.gz DotNetOpenAuth-bcdd8eb12670332b0de69752d583cba710490e38.tar.bz2 |
Perf tests now compare results against a baseline produced on the test machine.
This uses portions of MeasureIt, which normalizes perf measurements in terms of the machine's speed.
We also do other things to reduce noise:
* set process and thread priority
* wait for the CPU to quiet down before beginning.
* set power management to High Performance
* wake the CPU up if it's in a low power mode.
Diffstat (limited to 'src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs')
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs | 83 |
1 files changed, 28 insertions, 55 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs index 7984b58..fb1125e 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs @@ -19,6 +19,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { using DotNetOpenAuth.OpenId.Messages; using DotNetOpenAuth.OpenId.Provider; using NUnit.Framework; + using DotNetOpenAuth.Test.Performance; [TestFixture, Category("Performance")] public class PerformanceTests : OpenIdTestBase { @@ -29,73 +30,50 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { [SetUp] public override void SetUp() { base.SetUp(); - SuspendLogging(); this.provider = CreateProvider(); } - [TearDown] - public override void Cleanup() { - ResumeLogging(); - base.Cleanup(); - } - [TestCase] public void AssociateDH() { var associateRequest = this.CreateAssociateRequest(OPUri); - Stopwatch timer = new Stopwatch(); - timer.Start(); - int iterations; - for (iterations = 0; timer.ElapsedMilliseconds < TestRunTime.TotalMilliseconds; iterations++) { - IRequest request = this.provider.GetRequest(associateRequest); - var response = this.provider.PrepareResponse(request); - Assert.IsInstanceOf<AssociateSuccessfulResponse>(response.OriginalMessage); - } - timer.Stop(); - double executionsPerSecond = GetExecutionsPerSecond(iterations, timer); - TestUtilities.TestLogger.InfoFormat("Created {0} associations in {1}, or {2} per second.", iterations, timer.Elapsed, executionsPerSecond); - Assert.IsTrue(executionsPerSecond >= 2, "Too slow ({0} >= 2 executions per second required.)", executionsPerSecond); + PerformanceTestUtilities.Measure( + () => { + IRequest request = this.provider.GetRequest(associateRequest); + var response = this.provider.PrepareResponse(request); + Assert.IsInstanceOf<AssociateSuccessfulResponse>(response.OriginalMessage); + }, + maximumAllowedUnitTime: 2.8e6f, + iterations: 1); } [TestCase] public void AssociateClearText() { var associateRequest = this.CreateAssociateRequest(OPUriSsl); // SSL will cause a plaintext association - Stopwatch timer = new Stopwatch(); - timer.Start(); - int iterations; - for (iterations = 0; timer.ElapsedMilliseconds < TestRunTime.TotalMilliseconds; iterations++) { - IRequest request = this.provider.GetRequest(associateRequest); - var response = this.provider.PrepareResponse(request); - Assert.IsInstanceOf<AssociateSuccessfulResponse>(response.OriginalMessage); - } - timer.Stop(); - double executionsPerSecond = GetExecutionsPerSecond(iterations, timer); - TestUtilities.TestLogger.InfoFormat("Created {0} associations in {1}, or {2} per second.", iterations, timer.Elapsed, executionsPerSecond); - Assert.IsTrue(executionsPerSecond > 1000, "Too slow ({0} > 1000 executions per second required.)", executionsPerSecond); + PerformanceTestUtilities.Measure( + () => { + IRequest request = this.provider.GetRequest(associateRequest); + var response = this.provider.PrepareResponse(request); + Assert.IsInstanceOf<AssociateSuccessfulResponse>(response.OriginalMessage); + }, + maximumAllowedUnitTime: 1.2e4f, + iterations: 1000); } [TestCase] public void CheckIdSharedHmacSha1Association() { Protocol protocol = Protocol.Default; string assocType = protocol.Args.SignatureAlgorithm.HMAC_SHA1; - double executionsPerSecond = this.ParameterizedCheckIdTest(protocol, assocType); - TestUtilities.TestLogger.InfoFormat("{0} executions per second.", executionsPerSecond); - Assert.IsTrue(executionsPerSecond > 500, "Too slow ({0} > 500 executions per second required.)", executionsPerSecond); + this.ParameterizedCheckIdTest(protocol, assocType); } [TestCase] public void CheckIdSharedHmacSha256Association() { Protocol protocol = Protocol.Default; string assocType = protocol.Args.SignatureAlgorithm.HMAC_SHA256; - double executionsPerSecond = this.ParameterizedCheckIdTest(protocol, assocType); - TestUtilities.TestLogger.InfoFormat("{0} executions per second.", executionsPerSecond); - Assert.IsTrue(executionsPerSecond > 400, "Too slow ({0} > 400 executions per second required.)", executionsPerSecond); + this.ParameterizedCheckIdTest(protocol, assocType); } - private static double GetExecutionsPerSecond(int iterations, Stopwatch timer) { - return (double)iterations / (timer.ElapsedMilliseconds / 1000); - } - - private double ParameterizedCheckIdTest(Protocol protocol, string assocType) { + private void ParameterizedCheckIdTest(Protocol protocol, string assocType) { Association assoc = HmacShaAssociation.Create( protocol, assocType, @@ -103,19 +81,14 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { this.provider.SecuritySettings); this.provider.AssociationStore.StoreAssociation(AssociationRelyingPartyType.Smart, assoc); var checkidRequest = this.CreateCheckIdRequest(true); - Stopwatch timer = new Stopwatch(); - timer.Start(); - int iterations; - for (iterations = 0; timer.ElapsedMilliseconds < TestRunTime.TotalMilliseconds; iterations++) { - var request = (IAuthenticationRequest)this.provider.GetRequest(checkidRequest); - request.IsAuthenticated = true; - var response = this.provider.PrepareResponse(request); - Assert.IsInstanceOf<PositiveAssertionResponse>(response.OriginalMessage); - } - timer.Stop(); - double executionsPerSecond = GetExecutionsPerSecond(iterations, timer); - TestUtilities.TestLogger.InfoFormat("Responded to {0} checkid messages in {1}; or {2} authentications per second.", iterations, timer.Elapsed, executionsPerSecond); - return executionsPerSecond; + var stats = PerformanceTestUtilities.Measure( + () => { + var request = (IAuthenticationRequest)this.provider.GetRequest(checkidRequest); + request.IsAuthenticated = true; + var response = this.provider.PrepareResponse(request); + Assert.IsInstanceOf<PositiveAssertionResponse>(response.OriginalMessage); + }, + maximumAllowedUnitTime: 5.5e4f); } private HttpRequestInfo CreateAssociateRequest(Uri opEndpoint) { |