Created
February 28, 2011 00:08
-
-
Save joshhartman/846721 to your computer and use it in GitHub Desktop.
Get File Extension PHP Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = 'c:\\xampplite\\htdocs\\index.php'; | |
$max = 1000000; | |
?> | |
<p>Command: <strong>$ext = end(explode('.', $file));</strong></p> | |
<?php | |
// Start TIMER | |
$stimer = explode( ' ', microtime() ); | |
$stimer = $stimer[1] + $stimer[0]; | |
?> | |
<?php for($x=0; $x<$max; $x++){ ?> | |
<?php $ext = end(explode('.', $file)); echo ($x==0)?'Result: '.$ext:''; ?> | |
<?php } ?> | |
<?php | |
// End TIMER | |
$etimer = explode( ' ', microtime() ); | |
$etimer = $etimer[1] + $etimer[0]; | |
echo '<p>'; | |
printf( "Execution Time: <b>%f</b> seconds.", ($etimer-$stimer) ); | |
echo '</p>'; | |
?> | |
<p> </p> | |
<p>Command: <strong>$ext = substr($file, strrpos($file, '.')+1);</strong></p> | |
<?php | |
// Start TIMER | |
$stimer = explode( ' ', microtime() ); | |
$stimer = $stimer[1] + $stimer[0]; | |
?> | |
<?php for($x=0; $x<$max; $x++){ ?> | |
<?php $ext = substr($file, strrpos($file, '.')+1); echo ($x==0)?'Result: '.$ext:''; ?> | |
<?php } ?> | |
<?php | |
// End TIMER | |
$etimer = explode( ' ', microtime() ); | |
$etimer = $etimer[1] + $etimer[0]; | |
echo '<p>'; | |
printf( "Execution Time: <b>%f</b> seconds.", ($etimer-$stimer) ); | |
echo '</p>'; | |
?> | |
<p> </p> | |
<p>Command: <strong>$ext = pathinfo($file, PATHINFO_EXTENSION);</strong></p> | |
<?php | |
// Start TIMER | |
$stimer = explode( ' ', microtime() ); | |
$stimer = $stimer[1] + $stimer[0]; | |
?> | |
<?php for($x=0; $x<$max; $x++){ ?> | |
<?php $ext = pathinfo($file, PATHINFO_EXTENSION); echo ($x==0)?'Result: '.$ext:''; ?> | |
<?php } ?> | |
<?php | |
// End TIMER | |
$etimer = explode( ' ', microtime() ); | |
$etimer = $etimer[1] + $etimer[0]; | |
echo '<p>'; | |
printf( "Execution Time: <b>%f</b> seconds.", ($etimer-$stimer) ); | |
echo '</p>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment