Chinaunix首页 | 论坛 | 博客
  • 博客访问: 802363
  • 博文数量: 42
  • 博客积分: 10080
  • 博客等级: 上将
  • 技术积分: 1970
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-06 23:06
文章存档

2011年(1)

2010年(7)

2009年(4)

2008年(30)

我的朋友

分类:

2008-04-05 17:45:06

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$n = 100000;

print '1. (microtime): ';
$start = microtime(true);
for ($i=0; $i<$n; $i++) {
    $test = microtime();
}
print (microtime(true) - $start) . "s used \n";
print $test ."\n";

print '2. (microtime): ';
$start = microtime(true);
for ($i=0; $i<$n; $i++) {
    $test = microtime(true);
}
print (microtime(true) - $start) . "s used \n";
print $test ."\n";

print '3. uniqid: ';
$start = microtime(true);
for ($i=0; $i<$n; $i++) {
    $test = uniqid('uid', false);
}
print (microtime(true) - $start) . "s used \n";
print $test . "\n\n\n";


速度最快的是第三种
microtime()在php5后才支持传参返回float值,在多核的情况下,第2种方法也许会有重复值 ;在多机器环境下,要给值加不同的前缀区分不同的机器.还是原生php用的好。

阅读(1261) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~