I can do it? eg. if i want to check if str_replace() faster than preg_replace() ?
str_replace()
preg_replace()
You can run the same line 10,000 times (or more) in your script and use microtime(true) to indicate the time it took.
microtime(true)
Link: microtime ()
A simple way:
$time = microtime(true); // time in Microseconds // Your code here echo (microtime(true) - $time) . ' elapsed';
The hard (er) way: Use the code profiler to find out how long your methods will take.
I found this "bisko" answer in this thread.
$ start = microtime (true);for (...) {....}$ end = microtime (true);echo ($ end - $ start). 'seconds;
$ start = microtime (true);
for (...) {....}
$ end = microtime (true);
echo ($ end - $ start). 'seconds;
The for loop can be replaced at any time.