summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs')
-rw-r--r--src/DotNetOpenAuth.Test/Performance/PerformanceTestUtilities.cs56
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() {
+ }
+ }
+ }
+}