fork download
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. string[] vals = Enumerable.Range(0, 1000000).Select(n => n.ToString()).ToArray();
  10.  
  11. var watch = Stopwatch.StartNew();
  12.  
  13. List<string> res = vals.Select(x => string.Format("({0})", x)).ToList();
  14. Console.WriteLine ("it took {0} ms for string.Format", watch.ElapsedMilliseconds);
  15.  
  16. watch = Stopwatch.StartNew();
  17. for (int i = 0; i < vals.Length; i++)
  18. {
  19. vals[i] = "(" + vals[i] + ")";
  20. }
  21. Console.WriteLine ("it took {0} ms for " +"\'(\' + vals[i] +\')\';", watch.ElapsedMilliseconds);
  22. }
  23. }
Success #stdin #stdout 1.27s 148352KB
stdin
stdout
it took 706 ms for string.Format
it took 171 ms for '(' + vals[i]  +')';