我尝试测量PDO元素发送查询和检索答案所需的时间。
$db = new PDO('mysql:dbname=dbname;host=dbhost;charset=utf8', "username", "password");
$timing = -microtime(true);
$query = $db->prepare('SELECT * FROM table WHERE ID = 1');
$query->execute();
$result = $query->fetch();
var_dump($timing + microtime(true));
结果应该是大约0.0012秒,至少这是phpmyadmin显示的持续时间。但结果总是如此:
float(0)
是否存在某种舍入问题,我不知道?
答案 0 :(得分:2)
没有比手册更好的代码
$time_start = microtime(true);
//your code
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "it took $time seconds\n";