diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-03 07:49:30 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-03 07:49:30 -0700 |
commit | 8b17677ac0934a04b0a1547b06e178d3171a41b4 (patch) | |
tree | d3b410d7aa07dcc529f54e163bc0d6d0ec95ff49 | |
parent | b8690062e9ededc3c5d15d246f77ced834b11193 (diff) | |
download | DotNetOpenAuth-8b17677ac0934a04b0a1547b06e178d3171a41b4.zip DotNetOpenAuth-8b17677ac0934a04b0a1547b06e178d3171a41b4.tar.gz DotNetOpenAuth-8b17677ac0934a04b0a1547b06e178d3171a41b4.tar.bz2 |
Moved the performance measuring method into TestBase.
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs | 6 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs | 36 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/TestBase.cs | 30 |
3 files changed, 37 insertions, 35 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs index d35ac1d..84cb5c7 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs @@ -36,7 +36,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { [TestCase] public void AssociateDH() { var associateRequest = this.CreateAssociateRequest(OPUri); - PerformanceTestUtilities.Measure( + MeasurePerformance( () => { IRequest request = this.provider.GetRequest(associateRequest); var response = this.provider.PrepareResponse(request); @@ -49,7 +49,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { [TestCase] public void AssociateClearText() { var associateRequest = this.CreateAssociateRequest(OPUriSsl); // SSL will cause a plaintext association - PerformanceTestUtilities.Measure( + MeasurePerformance( () => { IRequest request = this.provider.GetRequest(associateRequest); var response = this.provider.PrepareResponse(request); @@ -81,7 +81,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { this.provider.SecuritySettings); this.provider.AssociationStore.StoreAssociation(AssociationRelyingPartyType.Smart, assoc); var checkidRequest = this.CreateCheckIdRequest(true); - var stats = PerformanceTestUtilities.Measure( + MeasurePerformance( () => { var request = (IAuthenticationRequest)this.provider.GetRequest(checkidRequest); request.IsAuthenticated = true; diff --git a/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs b/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs index 1b747aa..5e28732 100644 --- a/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs +++ b/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs @@ -13,44 +13,16 @@ namespace DotNetOpenAuth.Test.Performance { using NUnit.Framework; internal static class PerformanceTestUtilities { - private static Stats baseline; + internal static Stats Baseline; static PerformanceTestUtilities() { - baseline = CollectBaseline(); + Baseline = CollectBaseline(); TestUtilities.TestLogger.InfoFormat( "Scaled where EmptyStaticFunction = 1.0 ({0:f1} nsec = 1.0 units)", - baseline.Median * 1000); + Baseline.Median * 1000); } - internal static Stats Measure(Action action, float maximumAllowedUnitTime, int samples = 10, int iterations = 100, string name = null) { - if (!IsOptimized(typeof(OpenIdRelyingParty).Assembly)) { - Assert.Inconclusive("Unoptimized code."); - } - - var timer = new MultiSampleCodeTimer(samples, iterations); - Stats stats; - using (new HighPerformance()) { - stats = timer.Measure(name ?? TestContext.CurrentContext.Test.FullName, action); - } - - stats.AdjustForScale(PerformanceTestUtilities.baseline.Median); - - TestUtilities.TestLogger.InfoFormat( - "Performance counters: median {0}, mean {1}, min {2}, max {3}, stddev {4} ({5}%).", - stats.Median, - stats.Mean, - stats.Minimum, - stats.Maximum, - stats.StandardDeviation, - stats.StandardDeviation / stats.Median * 100); - - Assert.IsTrue(stats.Mean < maximumAllowedUnitTime, "The mean time of {0} exceeded the maximum allowable of {1}.", stats.Mean, maximumAllowedUnitTime); - TestUtilities.TestLogger.InfoFormat("Within {0}% of the maximum allowed time of {1}.", Math.Round((maximumAllowedUnitTime - stats.Mean) / maximumAllowedUnitTime * 100, 1), maximumAllowedUnitTime); - - return stats; - } - - private static bool IsOptimized(Assembly assembly) { + internal static bool IsOptimized(Assembly assembly) { DebuggableAttribute debugAttribute = (DebuggableAttribute)System.Attribute.GetCustomAttribute(assembly, typeof(System.Diagnostics.DebuggableAttribute)); return debugAttribute == null || !debugAttribute.IsJITOptimizerDisabled; } diff --git a/src/DotNetOpenAuth.Test/TestBase.cs b/src/DotNetOpenAuth.Test/TestBase.cs index 1c18c46..4a6eaca 100644 --- a/src/DotNetOpenAuth.Test/TestBase.cs +++ b/src/DotNetOpenAuth.Test/TestBase.cs @@ -11,6 +11,8 @@ namespace DotNetOpenAuth.Test { using System.Web; using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.OAuth.Messages; + using DotNetOpenAuth.OpenId.RelyingParty; + using DotNetOpenAuth.Test.Performance; using log4net; using NUnit.Framework; @@ -65,6 +67,34 @@ namespace DotNetOpenAuth.Test { log4net.LogManager.Shutdown(); } + internal static Stats MeasurePerformance(Action action, float maximumAllowedUnitTime, int samples = 10, int iterations = 100, string name = null) { + if (!PerformanceTestUtilities.IsOptimized(typeof(OpenIdRelyingParty).Assembly)) { + Assert.Inconclusive("Unoptimized code."); + } + + var timer = new MultiSampleCodeTimer(samples, iterations); + Stats stats; + using (new HighPerformance()) { + stats = timer.Measure(name ?? TestContext.CurrentContext.Test.FullName, action); + } + + stats.AdjustForScale(PerformanceTestUtilities.Baseline.Median); + + TestUtilities.TestLogger.InfoFormat( + "Performance counters: median {0}, mean {1}, min {2}, max {3}, stddev {4} ({5}%).", + stats.Median, + stats.Mean, + stats.Minimum, + stats.Maximum, + stats.StandardDeviation, + stats.StandardDeviation / stats.Median * 100); + + Assert.IsTrue(stats.Mean < maximumAllowedUnitTime, "The mean time of {0} exceeded the maximum allowable of {1}.", stats.Mean, maximumAllowedUnitTime); + TestUtilities.TestLogger.InfoFormat("Within {0}% of the maximum allowed time of {1}.", Math.Round((maximumAllowedUnitTime - stats.Mean) / maximumAllowedUnitTime * 100, 1), maximumAllowedUnitTime); + + return stats; + } + /// <summary> /// Sets HttpContext.Current to some empty (but non-null!) value. /// </summary> |