fork download
  1. using System;
  2. using System.Diagnostics;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Stopwatch watch;
  14.  
  15. string a, b, c, d, e, f, g, h;
  16. SetString(out a, out b, out c, out d, out e, out f, out g, out h);
  17.  
  18. int count = 1000000;
  19. string[] s = new string[count];
  20.  
  21. for (int loop = 0; loop < 8; loop++)
  22. {
  23. GC.Collect();
  24. watch = Stopwatch.StartNew();
  25. for (int i = 0; i < count; i++)
  26. {
  27. s[i] = a + b + c + d;
  28. }
  29. watch.Stop();
  30. Console.WriteLine("+:" + watch.ElapsedMilliseconds);
  31.  
  32. GC.Collect();
  33. watch = Stopwatch.StartNew();
  34. StringBuilder bulder = new StringBuilder();
  35. for (int i = 0; i < count; i++)
  36. {
  37. bulder.Append(a).Append(b).Append(c).Append(d);
  38. s[i] = bulder.ToString();
  39. bulder.Clear();
  40. }
  41. watch.Stop();
  42. Console.WriteLine("StringBuilder:" + watch.ElapsedMilliseconds);
  43. }
  44. }
  45.  
  46. [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
  47. static void SetString(out string a, out string b, out string c, out string d, out string e, out string f, out string g, out string h)
  48. {
  49. a = "AAAAAAAAAAAAAAAAA";
  50. b = "BBBBBBBBBBBBBBBBBBBBBBBB";
  51. c = "CCCCCCCCCCCCCCCCCCCC";
  52. d = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD";
  53. e = "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE";
  54. f = "FFFFFFFFFFFFFFFFFFFFFF";
  55. g = "GGGGGGGGGGGGGGGGG";
  56. h = "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH";
  57. }
  58.  
  59. }
  60. }
  61.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty