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