fork(2) download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4. using System.Diagnostics;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var sw = new Stopwatch();
  11. string s;
  12.  
  13. const int n = 20;
  14.  
  15. sw.Restart();
  16. s = "string";
  17. for (int q=0; q<n; ++q) s = Regex.Replace(s, "(.)(?=.)", "$1 ");
  18. sw.Stop();
  19. Console.WriteLine("{0} {1}", s.GetHashCode(), sw.ElapsedMilliseconds);
  20. GC.Collect();
  21.  
  22. sw.Restart();
  23. s = "string";
  24. for (int q=0; q<n; ++q) s = String.Join(" ", s.AsEnumerable());
  25. sw.Stop();
  26. Console.WriteLine("{0} {1}", s.GetHashCode(), sw.ElapsedMilliseconds);
  27. GC.Collect();
  28.  
  29. sw.Restart();
  30. s = "string";
  31. for (int q=0; q<n; ++q) s = String.Join(" ", s.ToCharArray());
  32. sw.Stop();
  33. Console.WriteLine("{0} {1}", s.GetHashCode(), sw.ElapsedMilliseconds);
  34. GC.Collect();
  35. }
  36. }
Success #stdin #stdout 3.34s 134720KB
stdin
Standard input is empty
stdout
539801481 2544
539801481 374
539801481 408