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/Performance/PerformanceTestUtilities.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/Performance/PerformanceTestUtilities.cs')
-rw-r--r-- | src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs b/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs new file mode 100644 index 0000000..5e28732 --- /dev/null +++ b/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs @@ -0,0 +1,56 @@ +//----------------------------------------------------------------------- +// <copyright file="PerformanceTestUtilities.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.Performance { + using System; + using System.Diagnostics; + using System.Reflection; + using System.Threading; + using DotNetOpenAuth.OpenId.RelyingParty; + using NUnit.Framework; + + internal static class PerformanceTestUtilities { + internal static Stats Baseline; + + static PerformanceTestUtilities() { + Baseline = CollectBaseline(); + TestUtilities.TestLogger.InfoFormat( + "Scaled where EmptyStaticFunction = 1.0 ({0:f1} nsec = 1.0 units)", + Baseline.Median * 1000); + } + + internal static bool IsOptimized(Assembly assembly) { + DebuggableAttribute debugAttribute = (DebuggableAttribute)System.Attribute.GetCustomAttribute(assembly, typeof(System.Diagnostics.DebuggableAttribute)); + return debugAttribute == null || !debugAttribute.IsJITOptimizerDisabled; + } + + private static Stats CollectBaseline() { + using (new HighPerformance()) { + return new MultiSampleCodeTimer(10, 1000).Measure( + "MethodCalls: EmptyStaticFunction()", + 10, + delegate { + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + }); + } + } + + private class Class { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + public static void EmptyStaticFunction() { + } + } + } +} |