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