From 6d25f9baf35f5cb2d245d56d73509c40763f9c36 Mon Sep 17 00:00:00 2001 From: Drew Scoggins Date: Tue, 25 Oct 2016 16:58:31 -0700 Subject: [PATCH] Update performance tests Add inner iterations to all performance tests in the perflab directory. This is because we were measuring a time that was to small, and the results were not useful. This should also reduce the number of high level iterations we run as well. Commit migrated from https://github.com/dotnet/coreclr/commit/e265939060ae690a3e971d80d60cdb5b45f734bb --- .../tests/src/performance/perflab/BlockCopyPerf.cs | 5 +- .../tests/src/performance/perflab/CastingPerf.cs | 122 +++-- .../tests/src/performance/perflab/CastingPerf2.cs | 77 ++-- .../tests/src/performance/perflab/DelegatePerf.cs | 35 +- .../tests/src/performance/perflab/EnumPerf.cs | 20 +- .../tests/src/performance/perflab/LowLevelPerf.cs | 216 +++++---- .../src/performance/perflab/ReflectionPerf.cs | 510 +++++++++++---------- .../tests/src/performance/perflab/StackWalk.cs | 5 +- .../tests/src/performance/perflab/ThreadingPerf.cs | 30 +- 9 files changed, 571 insertions(+), 449 deletions(-) diff --git a/src/coreclr/tests/src/performance/perflab/BlockCopyPerf.cs b/src/coreclr/tests/src/performance/perflab/BlockCopyPerf.cs index 5265983..076d436 100644 --- a/src/coreclr/tests/src/performance/perflab/BlockCopyPerf.cs +++ b/src/coreclr/tests/src/performance/perflab/BlockCopyPerf.cs @@ -7,7 +7,7 @@ using Xunit; public class BlockCopyPerf { - [Benchmark] + [Benchmark(InnerIterationCount=1000000)] [InlineData(0)] [InlineData(10)] [InlineData(100)] @@ -19,6 +19,7 @@ public class BlockCopyPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - Buffer.BlockCopy(bytes, 0, bytes, numElements, numElements); + for(int i=0; i>(); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - res = obj is IMyInterface1; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + res = obj is IMyInterface1; return res; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static bool CheckIsInstAnyIsInterfaceNo() { bool res = false; Object obj = new MyClass4>(); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - res = obj is IMyInterface2; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + res = obj is IMyInterface2; return res; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static bool CheckArrayIsInterfaceYes() { bool res = false; Object[] arr = new MyClass1[5]; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - res = arr is IMyInterface1[]; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + res = arr is IMyInterface1[]; return res; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static bool CheckArrayIsInterfaceNo() { bool res = false; Object[] arr = new MyClass2[5]; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - res = arr is IMyInterface1[]; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + res = arr is IMyInterface1[]; return res; } } diff --git a/src/coreclr/tests/src/performance/perflab/CastingPerf2.cs b/src/coreclr/tests/src/performance/perflab/CastingPerf2.cs index b2cc448..1f874a5 100644 --- a/src/coreclr/tests/src/performance/perflab/CastingPerf2.cs +++ b/src/coreclr/tests/src/performance/perflab/CastingPerf2.cs @@ -95,143 +95,158 @@ namespace CastingPerf2 public static IFoo ifo, ifo1, ifo2, ifo3, ifo4, ifo5, ifo6, ifo7, ifo8, ifo9; public static IFoo_5 if_0, if_1, if_2, if_3, if_4, if_5, if_6, if_7, if_8, if_9; - [Benchmark] + [Benchmark(InnerIterationCount=200000)] public static void ObjFooIsObj() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - o = foo; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + o = foo; } - [Benchmark] + [Benchmark(InnerIterationCount=200000)] public static void FooObjIsFoo() { o = foo; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - f = (Foo)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + f = (Foo)o; } - [Benchmark] + [Benchmark(InnerIterationCount=200000)] public static void FooObjIsNull() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - o = (Foo)n; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + o = (Foo)n; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void FooObjIsDescendant() { o = foo_5; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - f = (Foo)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + f = (Foo)o; } - [Benchmark] + [Benchmark(InnerIterationCount=200000)] public static void IFooFooIsIFoo() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - ifo = foo; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + ifo = foo; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void IFooObjIsIFoo() { o = foo; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - ifo = (IFoo)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + ifo = (IFoo)o; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void IFooObjIsIFooInterAlia() { o = foo2; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - if_0 = (IFoo_5)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + if_0 = (IFoo_5)o; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void IFooObjIsDescendantOfIFoo() { o = foo_5; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - ifo = (IFoo)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + ifo = (IFoo)o; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void ObjInt() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - o = (Object)j; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + o = (Object)j; } - [Benchmark] + [Benchmark(InnerIterationCount=200000)] public static void IntObj() { o = (Object)1; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - j = (int)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + j = (int)o; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void ObjScalarValueType() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - o = svt; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + o = svt; } - [Benchmark] + [Benchmark(InnerIterationCount=300000)] public static void ScalarValueTypeObj() { o = svt; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - svt = (FooSVT)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + svt = (FooSVT)o; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void ObjObjrefValueType() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - o = (Object)orvt; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + o = (Object)orvt; } - [Benchmark] + [Benchmark(InnerIterationCount=200000)] public static void ObjrefValueTypeObj() { o = (Object)orvt; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - orvt = (FooORVT)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + orvt = (FooORVT)o; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void FooObjCastIfIsa() { o = foo; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - if (o is Foo) - f = (Foo)o; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + if (o is Foo) + f = (Foo)o; } } } \ No newline at end of file diff --git a/src/coreclr/tests/src/performance/perflab/DelegatePerf.cs b/src/coreclr/tests/src/performance/perflab/DelegatePerf.cs index 667a352..abc311a 100644 --- a/src/coreclr/tests/src/performance/perflab/DelegatePerf.cs +++ b/src/coreclr/tests/src/performance/perflab/DelegatePerf.cs @@ -12,7 +12,7 @@ internal delegate int SerializeDelegate(); public class DelegatePerf { - [Benchmark] + [Benchmark(InnerIterationCount=200000)] public void DelegateInvoke() { DelegateLong dl = new DelegateLong(this.Invocable1); @@ -22,10 +22,11 @@ public class DelegatePerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - ret = dl(obj, 100, 100); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + ret = dl(obj, 100, 100); } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public void MulticastDelegateCombineInvoke() { MultiDelegate md = null; @@ -46,23 +47,26 @@ public class DelegatePerf using (iteration.StartMeasurement()) { - md = (MultiDelegate)Delegate.Combine(md1, md); - md = (MultiDelegate)Delegate.Combine(md2, md); - md = (MultiDelegate)Delegate.Combine(md3, md); - md = (MultiDelegate)Delegate.Combine(md4, md); - md = (MultiDelegate)Delegate.Combine(md5, md); - md = (MultiDelegate)Delegate.Combine(md6, md); - md = (MultiDelegate)Delegate.Combine(md7, md); - md = (MultiDelegate)Delegate.Combine(md8, md); - md = (MultiDelegate)Delegate.Combine(md9, md); - md = (MultiDelegate)Delegate.Combine(md10, md); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + md = (MultiDelegate)Delegate.Combine(md1, md); + md = (MultiDelegate)Delegate.Combine(md2, md); + md = (MultiDelegate)Delegate.Combine(md3, md); + md = (MultiDelegate)Delegate.Combine(md4, md); + md = (MultiDelegate)Delegate.Combine(md5, md); + md = (MultiDelegate)Delegate.Combine(md6, md); + md = (MultiDelegate)Delegate.Combine(md7, md); + md = (MultiDelegate)Delegate.Combine(md8, md); + md = (MultiDelegate)Delegate.Combine(md9, md); + md = (MultiDelegate)Delegate.Combine(md10, md); + } } } md(obj, 100, 100); } - [Benchmark] + [Benchmark(InnerIterationCount=10000)] [InlineData(100)] [InlineData(1000)] public void MulticastDelegateInvoke(int length) @@ -75,7 +79,8 @@ public class DelegatePerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - md(obj, 100, 100); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + md(obj, 100, 100); } internal virtual long Invocable1(Object obj, long x, long y) diff --git a/src/coreclr/tests/src/performance/perflab/EnumPerf.cs b/src/coreclr/tests/src/performance/perflab/EnumPerf.cs index 9e43572..bf8d89b 100644 --- a/src/coreclr/tests/src/performance/perflab/EnumPerf.cs +++ b/src/coreclr/tests/src/performance/perflab/EnumPerf.cs @@ -19,7 +19,7 @@ public enum Color public class EnumPerf { - [Benchmark] + [Benchmark(InnerIterationCount=300000)] [InlineData(Color.Red)] public static void EnumCompareTo(Color color) { @@ -27,10 +27,11 @@ public class EnumPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - color.CompareTo(white); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + color.CompareTo(white); } - [Benchmark] + [Benchmark(InnerIterationCount=300000)] public static Type ObjectGetType() { Type tmp = null; @@ -38,12 +39,13 @@ public class EnumPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - tmp = black.GetType(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + tmp = black.GetType(); return tmp; } - [Benchmark] + [Benchmark(InnerIterationCount=300000)] public static Type ObjectGetTypeNoBoxing() { Type tmp = null; @@ -51,12 +53,13 @@ public class EnumPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - tmp = black.GetType(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + tmp = black.GetType(); return tmp; } - [Benchmark] + [Benchmark(InnerIterationCount=300000)] public static bool EnumEquals() { Color black = Color.Black; @@ -65,7 +68,8 @@ public class EnumPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - tmp = black.Equals(white); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + tmp = black.Equals(white); return tmp; } diff --git a/src/coreclr/tests/src/performance/perflab/LowLevelPerf.cs b/src/coreclr/tests/src/performance/perflab/LowLevelPerf.cs index 76b3794..30c6734 100644 --- a/src/coreclr/tests/src/performance/perflab/LowLevelPerf.cs +++ b/src/coreclr/tests/src/performance/perflab/LowLevelPerf.cs @@ -9,49 +9,55 @@ using System.Runtime.CompilerServices; public class LowLevelPerf { - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void EmptyStaticFunction() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); - Class.EmptyStaticFunction(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + Class.EmptyStaticFunction(); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void EmptyStaticFunction5Arg() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); - Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + Class.EmptyStaticFunction5Arg(1, 2, 3, 4, 5); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void EmptyInstanceFunction() { Class aClass = new Class(); @@ -60,21 +66,24 @@ public class LowLevelPerf { using (iteration.StartMeasurement()) { - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); - aClass.EmptyInstanceFunction(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + aClass.EmptyInstanceFunction(); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void InterfaceInterfaceMethod() { AnInterface aInterface = new Class(); @@ -83,16 +92,19 @@ public class LowLevelPerf { using (iteration.StartMeasurement()) { - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface); + } } } } @@ -103,7 +115,7 @@ public class LowLevelPerf aInterface.InterfaceMethod(); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void InterfaceInterfaceMethodLongHierarchy() { AnInterface aInterface = new LongHierarchyChildClass(); @@ -123,10 +135,11 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - CallInterfaceMethod(aInterface); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + CallInterfaceMethod(aInterface); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void InterfaceInterfaceMethodSwitchCallType() { AnInterface aInterface = new LongHierarchyChildClass(); @@ -136,13 +149,16 @@ public class LowLevelPerf { using (iteration.StartMeasurement()) { - CallInterfaceMethod(aInterface); - CallInterfaceMethod(aInterface1); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + CallInterfaceMethod(aInterface); + CallInterfaceMethod(aInterface1); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static int ClassVirtualMethod() { SuperClass aClass = new Class(); @@ -150,42 +166,46 @@ public class LowLevelPerf int x = 0; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - x = aClass.VirtualMethod(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + x = aClass.VirtualMethod(); return x; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void SealedClassInterfaceMethod() { SealedClass aSealedClass = new SealedClass(); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aSealedClass.InterfaceMethod(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aSealedClass.InterfaceMethod(); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void StructWithInterfaceInterfaceMethod() { StructWithInterface aStructWithInterface = new StructWithInterface(); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aStructWithInterface.InterfaceMethod(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aStructWithInterface.InterfaceMethod(); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void StaticIntPlus() { Class aClass = new Class(); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - Class.aStaticInt += 1; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + Class.aStaticInt += 1; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static bool ObjectStringIsString() { object aObjectString = "aString1"; @@ -193,12 +213,13 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - b = aObjectString is String; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + b = aObjectString is String; return b; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void NewDelegateClassEmptyInstanceFn() { Class aClass = new Class(); @@ -206,10 +227,11 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aMyDelegate = new MyDelegate(aClass.EmptyInstanceFunction); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aMyDelegate = new MyDelegate(aClass.EmptyInstanceFunction); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void NewDelegateClassEmptyStaticFn() { Class aClass = new Class(); @@ -217,10 +239,11 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aMyDelegate = new MyDelegate(Class.EmptyStaticFunction); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aMyDelegate = new MyDelegate(Class.EmptyStaticFunction); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void InstanceDelegate() { Class aClass = new Class(); @@ -228,10 +251,11 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aInstanceDelegate(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aInstanceDelegate(); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void StaticDelegate() { Class aClass = new Class(); @@ -239,10 +263,11 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aStaticDelegate(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aStaticDelegate(); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void MeasureEvents() { Class aClass = new Class(); @@ -250,28 +275,31 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aClass.MeasureFire100(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aClass.MeasureFire100(); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void GenericClassWithIntGenericInstanceField() { GenericClass aGenericClassWithInt = new GenericClass(); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aGenericClassWithInt.aGenericInstanceFieldT = 1; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aGenericClassWithInt.aGenericInstanceFieldT = 1; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void GenericClassGenericStaticField() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - GenericClass.aGenericStaticFieldT = 1; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + GenericClass.aGenericStaticFieldT = 1; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static int GenericClassGenericInstanceMethod() { GenericClass aGenericClassWithInt = new GenericClass(); @@ -279,35 +307,38 @@ public class LowLevelPerf int x = 0; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - x = aGenericClassWithInt.ClassGenericInstanceMethod(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + x = aGenericClassWithInt.ClassGenericInstanceMethod(); return x; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static int GenericClassGenericStaticMethod() { int x = 0; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - x = GenericClass.ClassGenericStaticMethod(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + x = GenericClass.ClassGenericStaticMethod(); return x; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static int GenericGenericMethod() { // Warmup int x = 0; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - x = Class.GenericMethod(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + x = Class.GenericMethod(); return x; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void GenericClassWithSTringGenericInstanceMethod() { GenericClass aGenericClassWithString = new GenericClass(); @@ -315,10 +346,11 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - aGenericClassWithString.aGenericInstanceFieldT = aString; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + aGenericClassWithString.aGenericInstanceFieldT = aString; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static int ForeachOverList100Elements() { List iList = new List(); @@ -328,13 +360,14 @@ public class LowLevelPerf int iResult = 0; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - foreach (int i in iList) - iResult = i; + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + foreach (int j in iList) + iResult = j; return iResult; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static Type TypeReflectionObjectGetType() { Type type = null; @@ -342,12 +375,13 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - type = anObject.GetType(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + type = anObject.GetType(); return type; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static Type TypeReflectionArrayGetType() { Type type = null; @@ -355,12 +389,13 @@ public class LowLevelPerf foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - type = anArray.GetType(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + type = anArray.GetType(); return type; } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static string IntegerFormatting() { int number = Int32.MaxValue; @@ -368,7 +403,8 @@ public class LowLevelPerf string result = null; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - result = number.ToString(); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + result = number.ToString(); return result; } diff --git a/src/coreclr/tests/src/performance/perflab/ReflectionPerf.cs b/src/coreclr/tests/src/performance/perflab/ReflectionPerf.cs index a4b1086..954bbe7 100644 --- a/src/coreclr/tests/src/performance/perflab/ReflectionPerf.cs +++ b/src/coreclr/tests/src/performance/perflab/ReflectionPerf.cs @@ -56,345 +56,375 @@ public class GetMember s_t20 = typeof(Class20).GetTypeInfo(); } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetField() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredField("f1"); - s_t1.GetDeclaredField("f2"); - s_t1.GetDeclaredField("f3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredField("f1"); + s_t1.GetDeclaredField("f2"); + s_t1.GetDeclaredField("f3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod1() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); - s_t1.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); + s_t1.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod2() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod3() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); //TODO: check if we can really get the method - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); - s_t3.GetDeclaredMethod("m1"); - s_t3.GetDeclaredMethod("m2"); - s_t3.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); //TODO: check if we can really get the method + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + s_t3.GetDeclaredMethod("m1"); + s_t3.GetDeclaredMethod("m2"); + s_t3.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod4() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); //TODO: check if we can really get the method - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); - s_t3.GetDeclaredMethod("m1"); - s_t3.GetDeclaredMethod("m2"); - s_t3.GetDeclaredMethod("m3"); - s_t4.GetDeclaredMethod("m1"); - s_t4.GetDeclaredMethod("m2"); - s_t4.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); //TODO: check if we can really get the method + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + s_t3.GetDeclaredMethod("m1"); + s_t3.GetDeclaredMethod("m2"); + s_t3.GetDeclaredMethod("m3"); + s_t4.GetDeclaredMethod("m1"); + s_t4.GetDeclaredMethod("m2"); + s_t4.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod5() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); - s_t3.GetDeclaredMethod("m1"); - s_t3.GetDeclaredMethod("m2"); - s_t3.GetDeclaredMethod("m3"); - s_t4.GetDeclaredMethod("m1"); - s_t4.GetDeclaredMethod("m2"); - s_t4.GetDeclaredMethod("m3"); - s_t5.GetDeclaredMethod("m1"); - s_t5.GetDeclaredMethod("m2"); - s_t5.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + s_t3.GetDeclaredMethod("m1"); + s_t3.GetDeclaredMethod("m2"); + s_t3.GetDeclaredMethod("m3"); + s_t4.GetDeclaredMethod("m1"); + s_t4.GetDeclaredMethod("m2"); + s_t4.GetDeclaredMethod("m3"); + s_t5.GetDeclaredMethod("m1"); + s_t5.GetDeclaredMethod("m2"); + s_t5.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod10() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); - s_t3.GetDeclaredMethod("m1"); - s_t3.GetDeclaredMethod("m2"); - s_t3.GetDeclaredMethod("m3"); - s_t4.GetDeclaredMethod("m1"); - s_t4.GetDeclaredMethod("m2"); - s_t4.GetDeclaredMethod("m3"); - s_t5.GetDeclaredMethod("m1"); - s_t5.GetDeclaredMethod("m2"); - s_t5.GetDeclaredMethod("m3"); - - s_t6.GetDeclaredMethod("m1"); - s_t6.GetDeclaredMethod("m2"); - s_t6.GetDeclaredMethod("m3"); - s_t7.GetDeclaredMethod("m1"); - s_t7.GetDeclaredMethod("m2"); - s_t7.GetDeclaredMethod("m3"); - s_t8.GetDeclaredMethod("m1"); - s_t8.GetDeclaredMethod("m2"); - s_t8.GetDeclaredMethod("m3"); - s_t9.GetDeclaredMethod("m1"); - s_t9.GetDeclaredMethod("m2"); - s_t9.GetDeclaredMethod("m3"); - s_t10.GetDeclaredMethod("m1"); - s_t10.GetDeclaredMethod("m2"); - s_t10.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + s_t3.GetDeclaredMethod("m1"); + s_t3.GetDeclaredMethod("m2"); + s_t3.GetDeclaredMethod("m3"); + s_t4.GetDeclaredMethod("m1"); + s_t4.GetDeclaredMethod("m2"); + s_t4.GetDeclaredMethod("m3"); + s_t5.GetDeclaredMethod("m1"); + s_t5.GetDeclaredMethod("m2"); + s_t5.GetDeclaredMethod("m3"); + + s_t6.GetDeclaredMethod("m1"); + s_t6.GetDeclaredMethod("m2"); + s_t6.GetDeclaredMethod("m3"); + s_t7.GetDeclaredMethod("m1"); + s_t7.GetDeclaredMethod("m2"); + s_t7.GetDeclaredMethod("m3"); + s_t8.GetDeclaredMethod("m1"); + s_t8.GetDeclaredMethod("m2"); + s_t8.GetDeclaredMethod("m3"); + s_t9.GetDeclaredMethod("m1"); + s_t9.GetDeclaredMethod("m2"); + s_t9.GetDeclaredMethod("m3"); + s_t10.GetDeclaredMethod("m1"); + s_t10.GetDeclaredMethod("m2"); + s_t10.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod12() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); - s_t3.GetDeclaredMethod("m1"); - s_t3.GetDeclaredMethod("m2"); - s_t3.GetDeclaredMethod("m3"); - s_t4.GetDeclaredMethod("m1"); - s_t4.GetDeclaredMethod("m2"); - s_t4.GetDeclaredMethod("m3"); - s_t5.GetDeclaredMethod("m1"); - s_t5.GetDeclaredMethod("m2"); - s_t5.GetDeclaredMethod("m3"); - - s_t6.GetDeclaredMethod("m1"); - s_t6.GetDeclaredMethod("m2"); - s_t6.GetDeclaredMethod("m3"); - s_t7.GetDeclaredMethod("m1"); - s_t7.GetDeclaredMethod("m2"); - s_t7.GetDeclaredMethod("m3"); - s_t8.GetDeclaredMethod("m1"); - s_t8.GetDeclaredMethod("m2"); - s_t8.GetDeclaredMethod("m3"); - s_t9.GetDeclaredMethod("m1"); - s_t9.GetDeclaredMethod("m2"); - s_t9.GetDeclaredMethod("m3"); - s_t10.GetDeclaredMethod("m1"); - s_t10.GetDeclaredMethod("m2"); - s_t10.GetDeclaredMethod("m3"); - - s_t11.GetDeclaredMethod("m1"); - s_t11.GetDeclaredMethod("m2"); - s_t11.GetDeclaredMethod("m3"); - s_t12.GetDeclaredMethod("m1"); - s_t12.GetDeclaredMethod("m2"); - s_t12.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + s_t3.GetDeclaredMethod("m1"); + s_t3.GetDeclaredMethod("m2"); + s_t3.GetDeclaredMethod("m3"); + s_t4.GetDeclaredMethod("m1"); + s_t4.GetDeclaredMethod("m2"); + s_t4.GetDeclaredMethod("m3"); + s_t5.GetDeclaredMethod("m1"); + s_t5.GetDeclaredMethod("m2"); + s_t5.GetDeclaredMethod("m3"); + + s_t6.GetDeclaredMethod("m1"); + s_t6.GetDeclaredMethod("m2"); + s_t6.GetDeclaredMethod("m3"); + s_t7.GetDeclaredMethod("m1"); + s_t7.GetDeclaredMethod("m2"); + s_t7.GetDeclaredMethod("m3"); + s_t8.GetDeclaredMethod("m1"); + s_t8.GetDeclaredMethod("m2"); + s_t8.GetDeclaredMethod("m3"); + s_t9.GetDeclaredMethod("m1"); + s_t9.GetDeclaredMethod("m2"); + s_t9.GetDeclaredMethod("m3"); + s_t10.GetDeclaredMethod("m1"); + s_t10.GetDeclaredMethod("m2"); + s_t10.GetDeclaredMethod("m3"); + + s_t11.GetDeclaredMethod("m1"); + s_t11.GetDeclaredMethod("m2"); + s_t11.GetDeclaredMethod("m3"); + s_t12.GetDeclaredMethod("m1"); + s_t12.GetDeclaredMethod("m2"); + s_t12.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod15() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); - s_t3.GetDeclaredMethod("m1"); - s_t3.GetDeclaredMethod("m2"); - s_t3.GetDeclaredMethod("m3"); - s_t4.GetDeclaredMethod("m1"); - s_t4.GetDeclaredMethod("m2"); - s_t4.GetDeclaredMethod("m3"); - s_t5.GetDeclaredMethod("m1"); - s_t5.GetDeclaredMethod("m2"); - s_t5.GetDeclaredMethod("m3"); - - s_t6.GetDeclaredMethod("m1"); - s_t6.GetDeclaredMethod("m2"); - s_t6.GetDeclaredMethod("m3"); - s_t7.GetDeclaredMethod("m1"); - s_t7.GetDeclaredMethod("m2"); - s_t7.GetDeclaredMethod("m3"); - s_t8.GetDeclaredMethod("m1"); - s_t8.GetDeclaredMethod("m2"); - s_t8.GetDeclaredMethod("m3"); - s_t9.GetDeclaredMethod("m1"); - s_t9.GetDeclaredMethod("m2"); - s_t9.GetDeclaredMethod("m3"); - s_t10.GetDeclaredMethod("m1"); - s_t10.GetDeclaredMethod("m2"); - s_t10.GetDeclaredMethod("m3"); - - s_t11.GetDeclaredMethod("m1"); - s_t11.GetDeclaredMethod("m2"); - s_t11.GetDeclaredMethod("m3"); - s_t12.GetDeclaredMethod("m1"); - s_t12.GetDeclaredMethod("m2"); - s_t12.GetDeclaredMethod("m3"); - s_t13.GetDeclaredMethod("m1"); - s_t13.GetDeclaredMethod("m2"); - s_t13.GetDeclaredMethod("m3"); - s_t14.GetDeclaredMethod("m1"); - s_t14.GetDeclaredMethod("m2"); - s_t14.GetDeclaredMethod("m3"); - s_t15.GetDeclaredMethod("m1"); - s_t15.GetDeclaredMethod("m2"); - s_t15.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + s_t3.GetDeclaredMethod("m1"); + s_t3.GetDeclaredMethod("m2"); + s_t3.GetDeclaredMethod("m3"); + s_t4.GetDeclaredMethod("m1"); + s_t4.GetDeclaredMethod("m2"); + s_t4.GetDeclaredMethod("m3"); + s_t5.GetDeclaredMethod("m1"); + s_t5.GetDeclaredMethod("m2"); + s_t5.GetDeclaredMethod("m3"); + + s_t6.GetDeclaredMethod("m1"); + s_t6.GetDeclaredMethod("m2"); + s_t6.GetDeclaredMethod("m3"); + s_t7.GetDeclaredMethod("m1"); + s_t7.GetDeclaredMethod("m2"); + s_t7.GetDeclaredMethod("m3"); + s_t8.GetDeclaredMethod("m1"); + s_t8.GetDeclaredMethod("m2"); + s_t8.GetDeclaredMethod("m3"); + s_t9.GetDeclaredMethod("m1"); + s_t9.GetDeclaredMethod("m2"); + s_t9.GetDeclaredMethod("m3"); + s_t10.GetDeclaredMethod("m1"); + s_t10.GetDeclaredMethod("m2"); + s_t10.GetDeclaredMethod("m3"); + + s_t11.GetDeclaredMethod("m1"); + s_t11.GetDeclaredMethod("m2"); + s_t11.GetDeclaredMethod("m3"); + s_t12.GetDeclaredMethod("m1"); + s_t12.GetDeclaredMethod("m2"); + s_t12.GetDeclaredMethod("m3"); + s_t13.GetDeclaredMethod("m1"); + s_t13.GetDeclaredMethod("m2"); + s_t13.GetDeclaredMethod("m3"); + s_t14.GetDeclaredMethod("m1"); + s_t14.GetDeclaredMethod("m2"); + s_t14.GetDeclaredMethod("m3"); + s_t15.GetDeclaredMethod("m1"); + s_t15.GetDeclaredMethod("m2"); + s_t15.GetDeclaredMethod("m3"); + } } } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetMethod20() { foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { - s_t1.GetDeclaredMethod("m1"); - s_t1.GetDeclaredMethod("m2"); - s_t1.GetDeclaredMethod("m3"); - s_t2.GetDeclaredMethod("m1"); - s_t2.GetDeclaredMethod("m2"); - s_t2.GetDeclaredMethod("m3"); - s_t3.GetDeclaredMethod("m1"); - s_t3.GetDeclaredMethod("m2"); - s_t3.GetDeclaredMethod("m3"); - s_t4.GetDeclaredMethod("m1"); - s_t4.GetDeclaredMethod("m2"); - s_t4.GetDeclaredMethod("m3"); - s_t5.GetDeclaredMethod("m1"); - s_t5.GetDeclaredMethod("m2"); - s_t5.GetDeclaredMethod("m3"); - - s_t6.GetDeclaredMethod("m1"); - s_t6.GetDeclaredMethod("m2"); - s_t6.GetDeclaredMethod("m3"); - s_t7.GetDeclaredMethod("m1"); - s_t7.GetDeclaredMethod("m2"); - s_t7.GetDeclaredMethod("m3"); - s_t8.GetDeclaredMethod("m1"); - s_t8.GetDeclaredMethod("m2"); - s_t8.GetDeclaredMethod("m3"); - s_t9.GetDeclaredMethod("m1"); - s_t9.GetDeclaredMethod("m2"); - s_t9.GetDeclaredMethod("m3"); - s_t10.GetDeclaredMethod("m1"); - s_t10.GetDeclaredMethod("m2"); - s_t10.GetDeclaredMethod("m3"); - - s_t11.GetDeclaredMethod("m1"); - s_t11.GetDeclaredMethod("m2"); - s_t11.GetDeclaredMethod("m3"); - s_t12.GetDeclaredMethod("m1"); - s_t12.GetDeclaredMethod("m2"); - s_t12.GetDeclaredMethod("m3"); - s_t13.GetDeclaredMethod("m1"); - s_t13.GetDeclaredMethod("m2"); - s_t13.GetDeclaredMethod("m3"); - s_t14.GetDeclaredMethod("m1"); - s_t14.GetDeclaredMethod("m2"); - s_t14.GetDeclaredMethod("m3"); - s_t15.GetDeclaredMethod("m1"); - s_t15.GetDeclaredMethod("m2"); - s_t15.GetDeclaredMethod("m3"); - - s_t16.GetDeclaredMethod("m1"); - s_t16.GetDeclaredMethod("m2"); - s_t16.GetDeclaredMethod("m3"); - s_t17.GetDeclaredMethod("m1"); - s_t17.GetDeclaredMethod("m2"); - s_t17.GetDeclaredMethod("m3"); - s_t18.GetDeclaredMethod("m1"); - s_t18.GetDeclaredMethod("m2"); - s_t18.GetDeclaredMethod("m3"); - s_t19.GetDeclaredMethod("m1"); - s_t19.GetDeclaredMethod("m2"); - s_t19.GetDeclaredMethod("m3"); - s_t20.GetDeclaredMethod("m1"); - s_t20.GetDeclaredMethod("m2"); - s_t20.GetDeclaredMethod("m3"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + { + s_t1.GetDeclaredMethod("m1"); + s_t1.GetDeclaredMethod("m2"); + s_t1.GetDeclaredMethod("m3"); + s_t2.GetDeclaredMethod("m1"); + s_t2.GetDeclaredMethod("m2"); + s_t2.GetDeclaredMethod("m3"); + s_t3.GetDeclaredMethod("m1"); + s_t3.GetDeclaredMethod("m2"); + s_t3.GetDeclaredMethod("m3"); + s_t4.GetDeclaredMethod("m1"); + s_t4.GetDeclaredMethod("m2"); + s_t4.GetDeclaredMethod("m3"); + s_t5.GetDeclaredMethod("m1"); + s_t5.GetDeclaredMethod("m2"); + s_t5.GetDeclaredMethod("m3"); + + s_t6.GetDeclaredMethod("m1"); + s_t6.GetDeclaredMethod("m2"); + s_t6.GetDeclaredMethod("m3"); + s_t7.GetDeclaredMethod("m1"); + s_t7.GetDeclaredMethod("m2"); + s_t7.GetDeclaredMethod("m3"); + s_t8.GetDeclaredMethod("m1"); + s_t8.GetDeclaredMethod("m2"); + s_t8.GetDeclaredMethod("m3"); + s_t9.GetDeclaredMethod("m1"); + s_t9.GetDeclaredMethod("m2"); + s_t9.GetDeclaredMethod("m3"); + s_t10.GetDeclaredMethod("m1"); + s_t10.GetDeclaredMethod("m2"); + s_t10.GetDeclaredMethod("m3"); + + s_t11.GetDeclaredMethod("m1"); + s_t11.GetDeclaredMethod("m2"); + s_t11.GetDeclaredMethod("m3"); + s_t12.GetDeclaredMethod("m1"); + s_t12.GetDeclaredMethod("m2"); + s_t12.GetDeclaredMethod("m3"); + s_t13.GetDeclaredMethod("m1"); + s_t13.GetDeclaredMethod("m2"); + s_t13.GetDeclaredMethod("m3"); + s_t14.GetDeclaredMethod("m1"); + s_t14.GetDeclaredMethod("m2"); + s_t14.GetDeclaredMethod("m3"); + s_t15.GetDeclaredMethod("m1"); + s_t15.GetDeclaredMethod("m2"); + s_t15.GetDeclaredMethod("m3"); + + s_t16.GetDeclaredMethod("m1"); + s_t16.GetDeclaredMethod("m2"); + s_t16.GetDeclaredMethod("m3"); + s_t17.GetDeclaredMethod("m1"); + s_t17.GetDeclaredMethod("m2"); + s_t17.GetDeclaredMethod("m3"); + s_t18.GetDeclaredMethod("m1"); + s_t18.GetDeclaredMethod("m2"); + s_t18.GetDeclaredMethod("m3"); + s_t19.GetDeclaredMethod("m1"); + s_t19.GetDeclaredMethod("m2"); + s_t19.GetDeclaredMethod("m3"); + s_t20.GetDeclaredMethod("m1"); + s_t20.GetDeclaredMethod("m2"); + s_t20.GetDeclaredMethod("m3"); + } } } } /* - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetConstructor() { foreach (var iteration in Benchmark.Iterations) @@ -420,7 +450,7 @@ public class GetMember } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetProperty() { foreach (var iteration in Benchmark.Iterations) @@ -458,7 +488,7 @@ public class GetMember } } - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void GetEvent() { foreach (var iteration in Benchmark.Iterations) diff --git a/src/coreclr/tests/src/performance/perflab/StackWalk.cs b/src/coreclr/tests/src/performance/perflab/StackWalk.cs index 5a9eb88..da36fd0 100644 --- a/src/coreclr/tests/src/performance/perflab/StackWalk.cs +++ b/src/coreclr/tests/src/performance/perflab/StackWalk.cs @@ -7,7 +7,7 @@ using System.Runtime.CompilerServices; public static class StackWalk { - [Benchmark] + [Benchmark(InnerIterationCount=1000)] public static void Walk() { A(5); @@ -68,7 +68,8 @@ public static class StackWalk { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - GC.Collect(0); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + GC.Collect(0); return 55; } diff --git a/src/coreclr/tests/src/performance/perflab/ThreadingPerf.cs b/src/coreclr/tests/src/performance/perflab/ThreadingPerf.cs index f8f999f..5cb16d4 100644 --- a/src/coreclr/tests/src/performance/perflab/ThreadingPerf.cs +++ b/src/coreclr/tests/src/performance/perflab/ThreadingPerf.cs @@ -10,59 +10,65 @@ public class JITIntrinsics private static int s_i; private static string s_s; - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void CompareExchangeIntNoMatch() { s_i = 0; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - Interlocked.CompareExchange(ref s_i, 5, -1); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + Interlocked.CompareExchange(ref s_i, 5, -1); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void CompareExchangeIntMatch() { foreach (var iteration in Benchmark.Iterations) { s_i = 1; using (iteration.StartMeasurement()) - Interlocked.CompareExchange(ref s_i, 5, 1); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + Interlocked.CompareExchange(ref s_i, 5, 1); } } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void CompareExchangeObjNoMatch() { s_s = "Hello"; foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - Interlocked.CompareExchange(ref s_s, "World", "What?"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + Interlocked.CompareExchange(ref s_s, "World", "What?"); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void CompareExchangeObjMatch() { foreach (var iteration in Benchmark.Iterations) { s_s = "What?"; using (iteration.StartMeasurement()) - Interlocked.CompareExchange(ref s_s, "World", "What?"); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + Interlocked.CompareExchange(ref s_s, "World", "What?"); } } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void InterlockedIncrement() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - Interlocked.Increment(ref s_i); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + Interlocked.Increment(ref s_i); } - [Benchmark] + [Benchmark(InnerIterationCount=100000)] public static void InterlockedDecrement() { foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) - Interlocked.Decrement(ref s_i); + for (int i = 0; i < Benchmark.InnerIterationCount; i++) + Interlocked.Decrement(ref s_i); } } \ No newline at end of file -- 2.7.4