start(); foreach($c as $v){ in_array($v, $a, true); } $time1->stop(); $time2 = new runtime; $time2->start(); $b = array_flip($a); foreach($c as $v){ isset($b[$v]); } $time2->stop(); function random($length) { $hash = ''; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max = strlen($chars) - 1; for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; } class runtime { var $StartTime = 0; var $StopTime = 0; function get_microtime() { list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } function start() { $this->StartTime = $this->get_microtime(); } function stop() { $this->StopTime = $this->get_microtime(); } function spent() { return round(($this->StopTime - $this->StartTime) * 1000, 5); } } ?>
测试基础数组长度:
测试待查询数组长度:
0 && $q > 0) { echo "in_array:".$time1->spent()."ms
"; echo "isset(array_flip()):".$time2->spent()."ms
"; }else{ echo "请输入整数测试"; } ?>