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 = 100000;
  19. string[] s = new string[count];
  20.  
  21. for (int loop = 0; loop < 4; loop++)
  22. {
  23. watch = Stopwatch.StartNew();
  24. for (int i = 0; i < count; i++)
  25. {
  26. s[i] = a + b + c + d + e + f + g + h;
  27. }
  28. watch.Stop();
  29. Console.WriteLine("+:" + watch.ElapsedMilliseconds);
  30.  
  31. watch = Stopwatch.StartNew();
  32. StringBuilder bulder = new StringBuilder();
  33. for (int i = 0; i < count; i++)
  34. {
  35. bulder.Append(a).Append(b).Append(c).Append(d).Append(e).Append(f).Append(g).Append(h);
  36. s[i] = bulder.ToString();
  37. bulder.Clear();
  38. }
  39. watch.Stop();
  40. Console.WriteLine("StringBuilder:" + watch.ElapsedMilliseconds);
  41. }
  42. }
  43.  
  44. [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
  45. 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)
  46. {
  47. a = "AAAAAAAAAAAAAAAAA";
  48. b = "BBBBBBBBBBBBBBBBBBBBBBBB";
  49. c = "CCCCCCCCCCCCCCCCCCCC";
  50. d = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD";
  51. e = "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE";
  52. f = "FFFFFFFFFFFFFFFFFFFFFF";
  53. g = "GGGGGGGGGGGGGGGGG";
  54. h = "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH";
  55. }
  56.  
  57. }
  58. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty