最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php测试性能代码
时间:2022-07-02 10:37:45 编辑:袖梨 来源:一聚教程网
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 < $length; $i ++) {
$array['abc' . $i] = 'abc' . $i;
}
echotime('start');
for ($i = 0; $i < $loop; $i ++) {
if (array_key_exists($key, $array)) {
$a = true;
}
}
echotime('array_key_exists');
for ($i = 0; $i < $loop; $i ++) {
if (isset($array[$key])) {
$a = true;
}
}
echotime('isset');
for ($i = 0; $i < $loop; $i ++) {
if (in_array($key, $array)) {
$a = true;
}
}
echotime('in_array');
for ($i = 0; $i < $loop; $i ++) {
if (array_search($key, $array)) {
$a = true;
}
}
echotime('array_search');
$array2 = array_flip($array);
for ($i = 0; $i < $loop; $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');
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22