Add DateTime performance test
authorMatt Connew <mconnew@microsoft.com>
Wed, 15 Jun 2016 22:03:40 +0000 (15:03 -0700)
committerMatt Connew <mconnew@microsoft.com>
Wed, 22 Jun 2016 18:53:10 +0000 (11:53 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/162f06b4fbdb2e2067c4c4e871ccd607b743a765

src/libraries/System.Runtime.Serialization.Xml/tests/Performance/PerformanceTestsCommon.cs

index 98d3a4e..60975c5 100644 (file)
@@ -21,7 +21,8 @@ namespace System.Runtime.Serialization
         ListOfInt,
         String,
         ByteArray,
-        XmlElement
+        XmlElement,
+        DateTimeArray
     }
 
     public interface IPerfTestSerializer
@@ -78,6 +79,7 @@ namespace System.Runtime.Serialization
             yield return new PerfTestConfig(1, TestType.SimpleType, 15);
             yield return new PerfTestConfig(10000, TestType.ISerializable, -1);
             yield return new PerfTestConfig(10000, TestType.XmlElement, -1);
+            yield return new PerfTestConfig(100, TestType.DateTimeArray, 1024);
         }
 
         public static IEnumerable<object[]> PerformanceMemberData()
@@ -146,6 +148,22 @@ namespace System.Runtime.Serialization
             return Enumerable.Range(0, count).ToList();
         }
 
+        public static DateTime[] CreateDateTimeArray(int count)
+        {
+            DateTime[] arr = new DateTime[count];
+            int kind = (int)DateTimeKind.Unspecified;
+            int maxDateTimeKind = (int) DateTimeKind.Local;
+            DateTime val = DateTime.Now.AddHours(count/2);
+            for (int i = 0; i < count; i++)
+            {
+                arr[i] = DateTime.SpecifyKind(val, (DateTimeKind)kind);
+                val = val.AddHours(1);
+                kind = (kind + 1)%maxDateTimeKind;
+            }
+
+            return arr;
+        }
+
         public static object GetSerializationObject(TestType testType, int testSize)
         {
             Object obj = null;
@@ -176,6 +194,9 @@ namespace System.Runtime.Serialization
                     xmlElement.InnerText = "Element innertext";
                     obj = xmlElement;
                     break;
+                case TestType.DateTimeArray:
+                    obj = CreateDateTimeArray(testSize);
+                    break;
                 default:
                     throw new ArgumentException();
             }