public void TestStructVsClass() { HiPerfTimer timer = new HiPerfTimer(); const int num = 1000000; timer.Start(); List <MyClass> classes = new List <MyClass>(num); for (int i = 0; i < num; i++) { classes.Add(new MyClass(i)); } timer.Stop(); Console.WriteLine("Constructing {0} classes: {1}", num, timer.Duration.ToString()); timer.Start(); List <MyStruct> structs = new List <MyStruct>(num); for (int i = 0; i < num; i++) { structs.Add(new MyStruct(i)); } timer.Stop(); Console.WriteLine("Constructing {0} structs: {1}", num, timer.Duration.ToString()); timer.Start(); MyClassWithSmallClasses test1 = new MyClassWithSmallClasses(num); timer.Stop(); Console.WriteLine("Duration to construct large class containing smaller classes: " + timer.Duration.ToString()); timer.Start(); MyClassWithSmallStructs test2 = new MyClassWithSmallStructs(num); timer.Stop(); Console.WriteLine("Duration to construct large class containing smaller structs: " + timer.Duration.ToString()); }
public void TestStructVsClass() { HiPerfTimer timer = new HiPerfTimer(); const int num = 1000000; timer.Start(); List<MyClass> classes = new List<MyClass>(num); for (int i = 0; i < num; i++) classes.Add(new MyClass(i)); timer.Stop(); Console.WriteLine("Constructing {0} classes: {1}", num, timer.Duration.ToString()); timer.Start(); List<MyStruct> structs = new List<MyStruct>(num); for (int i = 0; i < num; i++) structs.Add(new MyStruct(i)); timer.Stop(); Console.WriteLine("Constructing {0} structs: {1}", num, timer.Duration.ToString()); timer.Start(); MyClassWithSmallClasses test1 = new MyClassWithSmallClasses(num); timer.Stop(); Console.WriteLine("Duration to construct large class containing smaller classes: " + timer.Duration.ToString()); timer.Start(); MyClassWithSmallStructs test2 = new MyClassWithSmallStructs(num); timer.Stop(); Console.WriteLine("Duration to construct large class containing smaller structs: " + timer.Duration.ToString()); }