|
<?php
|
|
|
|
$times = 50000;
|
|
|
|
function isFirstPartOfStrNewSingleReturn ($str, $partStr) {
|
|
if ($partStr === '') {
|
|
$return = FALSE;
|
|
}
|
|
else {
|
|
if (strpos($str, $partStr, 0) === 0) {
|
|
$return = TRUE;
|
|
}
|
|
else {
|
|
$return = FALSE;
|
|
}
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
function isFirstPartOfStrNewSingleReturnShort ($str, $partStr) {
|
|
$return = FALSE;
|
|
if ($partStr !== '') {
|
|
if (strpos($str, $partStr, 0) === 0) {
|
|
$return = TRUE;
|
|
}
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
function isFirstPartOfStrNew ($str, $partStr) {
|
|
if ($partStr === '') return FALSE;
|
|
if (strpos($str, $partStr, 0) === 0) {
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
function isFirstPartOfStrOld ($str, $partStr) {
|
|
$psLen = strlen($partStr);
|
|
if ($psLen) {
|
|
return substr($str, 0, $psLen) == (string)$partStr;
|
|
} else return FALSE;
|
|
}
|
|
|
|
function test ($function, $a, $b) {
|
|
global $times;
|
|
$time_start = microtime(TRUE);
|
|
for ($i = 0; $i < $times; $i++) {
|
|
$function($a, $b);
|
|
}
|
|
return (microtime(TRUE) - $time_start);
|
|
}
|
|
|
|
$time_old_normal = test ('isFirstPartOfStrOld', 'the quick brown fox', 'the');
|
|
$time_old_empty = test ('isFirstPartOfStrOld', 'the quick brown fox', '');
|
|
$time_new_normal = test ('isFirstPartOfStrNew', 'the quick brown fox', 'the');
|
|
$time_new_empty = test ('isFirstPartOfStrNew', 'the quick brown fox', '');
|
|
$time_new_singlereturn_normal = test ('isFirstPartOfStrNewSingleReturn', 'the quick brown fox', 'the');
|
|
$time_new_singlereturnshort_normal = test ('isFirstPartOfStrNewSingleReturnShort', 'the quick brown fox', 'the');
|
|
$time_new_singlereturn_empty = test ('isFirstPartOfStrNewSingleReturn', 'the quick brown fox', '');
|
|
$time_new_singlereturnshort_empty = test ('isFirstPartOfStrNewSingleReturnShort', 'the quick brown fox', '');
|
|
|
|
echo "old plain : " . $time_old_normal;
|
|
echo "\nnew plain : " . $time_new_normal . ' gain: ' . number_format((($time_old_normal/$time_new_normal)*100) - 100, 1) . ' %';
|
|
echo "\nnew single return: " . $time_new_singlereturn_normal . ' gain: ' . number_format((($time_old_normal/$time_new_singlereturn_normal)*100) - 100, 1) . ' %';
|
|
echo "\nnew single short : " . $time_new_singlereturnshort_normal . ' gain: ' . number_format((($time_old_normal/$time_new_singlereturnshort_normal)*100) - 100, 1) . ' %';
|
|
;
|
|
echo "\n";
|
|
echo "\nold empty : " . $time_old_empty;
|
|
echo "\nnew empty : " . $time_new_empty . "gain : " . number_format((($time_old_empty/$time_new_empty)*100) - 100, 1) . ' %';;
|
|
echo "\nnew single return: " . $time_new_singlereturn_empty . "gain : " . number_format((($time_old_empty/$time_new_singlereturn_empty)*100) - 100, 1) . ' %';;
|
|
;
|
|
echo "\nnew single short : " . $time_new_singlereturnshort_empty . "gain : " . number_format((($time_old_empty/$time_new_singlereturnshort_empty)*100) - 100, 1) . ' %';;
|
|
;
|
|
|
|
?>
|