fork download
  1. <?php
  2. $loop=1000;
  3.  
  4. $str=implode('', array_fill(0, 3000, base64_encode(mt_rand())));
  5.  
  6. $time = microtime(true);
  7. for($n=0;$n<$loop;$n++)
  8. $s = str_replace("c", "", str_replace("b", "", str_replace("a", "", $str)));
  9. $time = microtime(true)-$time; echo "$time\n";
  10.  
  11. $time = microtime(true);
  12. $A=["a", "b", "c"];
  13. for($n=0;$n<$loop;$n++)
  14. $s = str_replace( $A, "", $str);
  15. $time = microtime(true)-$time; echo "$time\n";
  16.  
  17. $time = microtime(true);
  18. $A=["a", "b", "c"]; $B=["", "", ""];
  19. for($n=0;$n<$loop;$n++)
  20. $s = str_replace( $A, $B, $str);
  21. $time = microtime(true)-$time; echo "$time\n";
  22.  
  23. $time = microtime(true);
  24. for($n=0;$n<$loop;$n++)
  25. $s = preg_replace('/[abc]/', '', $str);
  26. $time = microtime(true)-$time; echo "$time\n";
  27.  
  28. $time = microtime(true);
  29. $A = ['a' => '', 'b' => '', 'c' => ''];
  30. for($n=0;$n<$loop;$n++)
  31. $s = strtr($str, $A);
  32. $time = microtime(true)-$time; echo "$time\n";
Success #stdin #stdout 4.72s 52472KB
stdin
Standard input is empty
stdout
0.25582218170166
0.27555298805237
0.27600812911987
3.1916019916534
0.75007677078247