diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-03 17:17:56 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-03 17:17:56 -0700 |
commit | 698d585be11f67b5c8e6cbca7070a907cb1079a8 (patch) | |
tree | d3b410d7aa07dcc529f54e163bc0d6d0ec95ff49 /src/DotNetOpenAuth.Test/TestBase.cs | |
parent | 6c751fc1364d94733e099c3a21623033c85ad86d (diff) | |
parent | 8b17677ac0934a04b0a1547b06e178d3171a41b4 (diff) | |
download | DotNetOpenAuth-698d585be11f67b5c8e6cbca7070a907cb1079a8.zip DotNetOpenAuth-698d585be11f67b5c8e6cbca7070a907cb1079a8.tar.gz DotNetOpenAuth-698d585be11f67b5c8e6cbca7070a907cb1079a8.tar.bz2 |
Stabilized performance tests against differences in hardware.
Diffstat (limited to 'src/DotNetOpenAuth.Test/TestBase.cs')
-rw-r--r-- | src/DotNetOpenAuth.Test/TestBase.cs | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/DotNetOpenAuth.Test/TestBase.cs b/src/DotNetOpenAuth.Test/TestBase.cs index 8aeca2d..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> @@ -73,15 +103,5 @@ namespace DotNetOpenAuth.Test { new HttpRequest("mock", "http://mock", "mock"), new HttpResponse(new StringWriter())); } - -#pragma warning disable 0618 - protected internal static void SuspendLogging() { - LogManager.GetLoggerRepository().Threshold = LogManager.GetLoggerRepository().LevelMap["OFF"]; - } - - protected internal static void ResumeLogging() { - LogManager.GetLoggerRepository().Threshold = LogManager.GetLoggerRepository().LevelMap["ALL"]; - } -#pragma warning restore 0618 } } |