summaryrefslogtreecommitdiff
path: root/tests/src/performance/perflab/EnumPerf.cs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/performance/perflab/EnumPerf.cs')
-rw-r--r--tests/src/performance/perflab/EnumPerf.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/src/performance/perflab/EnumPerf.cs b/tests/src/performance/perflab/EnumPerf.cs
new file mode 100644
index 0000000000..bf8d89b476
--- /dev/null
+++ b/tests/src/performance/perflab/EnumPerf.cs
@@ -0,0 +1,76 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Reflection;
+using Xunit;
+
+public enum Color
+{
+ Black,
+ White,
+ Red,
+ Brown,
+ Yellow,
+ Purple,
+ Orange
+}
+
+public class EnumPerf
+{
+ [Benchmark(InnerIterationCount=300000)]
+ [InlineData(Color.Red)]
+ public static void EnumCompareTo(Color color)
+ {
+ Color white = Color.White;
+
+ foreach (var iteration in Benchmark.Iterations)
+ using (iteration.StartMeasurement())
+ for (int i = 0; i < Benchmark.InnerIterationCount; i++)
+ color.CompareTo(white);
+ }
+
+ [Benchmark(InnerIterationCount=300000)]
+ public static Type ObjectGetType()
+ {
+ Type tmp = null;
+ Color black = Color.Black;
+
+ foreach (var iteration in Benchmark.Iterations)
+ using (iteration.StartMeasurement())
+ for (int i = 0; i < Benchmark.InnerIterationCount; i++)
+ tmp = black.GetType();
+
+ return tmp;
+ }
+
+ [Benchmark(InnerIterationCount=300000)]
+ public static Type ObjectGetTypeNoBoxing()
+ {
+ Type tmp = null;
+ object black = Color.Black;
+
+ foreach (var iteration in Benchmark.Iterations)
+ using (iteration.StartMeasurement())
+ for (int i = 0; i < Benchmark.InnerIterationCount; i++)
+ tmp = black.GetType();
+
+ return tmp;
+ }
+
+ [Benchmark(InnerIterationCount=300000)]
+ public static bool EnumEquals()
+ {
+ Color black = Color.Black;
+ Color white = Color.White;
+ bool tmp = false;
+
+ foreach (var iteration in Benchmark.Iterations)
+ using (iteration.StartMeasurement())
+ for (int i = 0; i < Benchmark.InnerIterationCount; i++)
+ tmp = black.Equals(white);
+
+ return tmp;
+ }
+}