Created
July 16, 2018 11:24
-
-
Save jhdxr/24c5b8017f3a80b22e2a23b7c01b6e70 to your computer and use it in GitHub Desktop.
benchmark for php_strip_whitespace
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 | |
$i = 5000; | |
$t = start_test(); | |
while($i--){ | |
php_strip_whitespace(__FILE__); | |
} | |
end_test($t, 'total'); | |
//following utils copy from Zend/bench.php | |
function getmicrotime() | |
{ | |
$t = gettimeofday(); | |
return ($t['sec'] + $t['usec'] / 1000000); | |
} | |
function start_test() | |
{ | |
ob_start(); | |
return getmicrotime(); | |
} | |
function end_test($start, $name) | |
{ | |
global $total; | |
$end = getmicrotime(); | |
ob_end_clean(); | |
$total += $end-$start; | |
$num = number_format($end-$start,3); | |
$pad = str_repeat(" ", 24-strlen($name)-strlen($num)); | |
echo $name.$pad.$num."\n"; | |
ob_start(); | |
return getmicrotime(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jhdxr Have you considered to use hrtime()?