Heim  >  Artikel  >  Backend-Entwicklung  >  php测试性能代码_PHP教程

php测试性能代码_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:52:211076Durchsuche

php测试性能代码

function microtime_float ()
{
    list ($usec, $sec) = explode(" ", microtime());
    return ((float) $usec + (float) $sec);
}
function echotime ($name)
{
    static $t_start = 0;
    $t_end = microtime_float();
    if ($name != 'start') {
        $time = $t_end - $t_start;
        echo ($name . ':');
        echo intval($time * 1000);
        echo "
\n";
    }
    $t_start = $t_end;
}
$index = 1000;
$loop = 10000;
$length = 10000;
$key = "abc" . $index;
$array = array();
for ($i = 0; $i     $array['abc' . $i] = 'abc' . $i;
}
echotime('start');
for ($i = 0; $i     if (array_key_exists($key, $array)) {
        $a = true;
    }
}
echotime('array_key_exists');
for ($i = 0; $i     if (isset($array[$key])) {
        $a = true;
    }
}
echotime('isset');
for ($i = 0; $i     if (in_array($key, $array)) {
        $a = true;
    }
}
echotime('in_array');
for ($i = 0; $i     if (array_search($key, $array)) {
        $a = true;
    }
}
echotime('array_search');
$array2 = array_flip($array);
for ($i = 0; $i     if (isset($array2[$key])) {
        $a = true;
    }
}
echotime('flip and search');
$array2 = $array;
foreach ($array2 as $k => $v) {
    $array2[$k] = strtoupper($v);
}
echotime('foreach1');
$array2 = $array;
foreach ($array2 as &$v) {
    $v = strtoupper($v);
}
echotime('foreach2');
$array2 = $array;
$array2 = array_map('strtoupper', $array2);
echotime('array_map');

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632488.htmlTechArticlephp测试性能代码 function microtime_float () { list ($usec, $sec) = explode( , microtime()); return ((float) $usec + (float) $sec); } function echotime ($name) { static $t_sta...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn