假设我必须通过php对象执行MySQL查询,那么有什么更好的方法呢?让方法明确地返回一条记录并调用此方法--让其调用1000次(更改参数),或者在一次调用中给该方法1000的范围,并返回1000条记录?都是在速度/性能方面。
发布于 2014-02-02 01:47:05
没有什么比小小的锻炼更好的了
如果你想找点乐子,你可以自己试试:
function getOneRecordAtATime()
{
for ($i = 0; $i < 1000; $i++)
{
// call the db and retrieve one record
}
}
function getAllRecords()
{
// call the db once and retrieve 1000 records
}
$startOne = microtime(true);
getOneRecordAtATime();
$endOne = microtime(true);
$startTwo = microtime(true);
getAllRecords();
$endTwo = microtime(true);
$timeOne = ($endOne - $startOne) * 1000;
$timeTwo = ($endTwo - $startTwo) * 1000;
print "Time to fetch one record at a time, 1000 times : ".$timeOne." ms\n";
print "Time to fetch 1000 records at once : ".$timeTwo." ms\n";告诉我们结果;)
https://stackoverflow.com/questions/21505433
复制相似问题