<?php
function chopExtension1($filename) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
return preg_replace('/\.' . preg_quote($ext, '/') . '$/', '', $filename);
}
function chopExtension2($filename) {
return substr($filename, 0, strrpos($filename, '.'));
}
$now1 = microtime();
foreach(range(1, 1000) as $i) {
chopExtension1('bob.php');
}
$duration1 = microtime() - $now;
$now2 = microtime();
foreach(range(1, 1000) as $i) {
chopExtension2('bob.php');
}
$duration2 = microtime() - $now2;
echo $duration1 . ' ' . $duration2;
echo 'difference => ' . ($duration1 - $duration2);