Skip to content

Instantly share code, notes, and snippets.

@jhdxr
Created July 16, 2018 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhdxr/24c5b8017f3a80b22e2a23b7c01b6e70 to your computer and use it in GitHub Desktop.
Save jhdxr/24c5b8017f3a80b22e2a23b7c01b6e70 to your computer and use it in GitHub Desktop.
benchmark for php_strip_whitespace
<?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();
}
@cmb69
Copy link

cmb69 commented Jul 22, 2018

@jhdxr Have you considered to use hrtime()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment