- pathinfo: documentation ( source)
- microtime: documentation ( source)
- preg_match: documentation ( source)
<?php
$filename = 'test/test/foo/bar/baz.php';
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
in_array(pathinfo( $filename, PATHINFO_EXTENSION ), ['php', 'phtml']);
}
echo 'in_array: ' . ( microtime(true) - $start ) . "\n";
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
preg_match('/\.(?:php|phtml)/i', $filename);
}
echo 'preg: ' . ( microtime(true) - $start );