fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace A
  7. {
  8. struct MyStruct { public string X; public string Y; public string O; }
  9. class MyClass { public string X; public string Y; public string O; }
  10.  
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. fooY();
  16. fooZ();
  17. Console.ReadKey();
  18. }
  19.  
  20. private static void fooY()
  21. {
  22. var sw = new System.Diagnostics.Stopwatch();
  23. sw.Start();
  24. for (int k = 0; k < 100; k++)
  25. for (int i = 0; i < 10000; i++)
  26. {
  27. var t = new MyStruct(); t.X = "aaaa"; t.Y = "bbbb"; t.O = t.X + t.Y;
  28. };
  29. sw.Stop();
  30. Console.WriteLine("MyStruct : {0}", sw.ElapsedMilliseconds);
  31. }
  32.  
  33. private static void fooZ()
  34. {
  35. var sw = new System.Diagnostics.Stopwatch();
  36. sw.Start();
  37. for (int k = 0; k < 100; k++)
  38. for (int i = 0; i < 10000; i++)
  39. {
  40. var t = new MyClass(); t.X = "aaaa"; t.Y = "bbbb"; t.O = t.X + t.Y;
  41. };
  42. sw.Stop();
  43. Console.WriteLine("MyClass : {0}", sw.ElapsedMilliseconds);
  44. }
  45. }
  46. }
  47.  
  48.  
  49.  
Success #stdin #stdout 0.27s 34152KB
stdin
Standard input is empty
stdout
MyStruct : 98
MyClass : 142