Php/MySQL Performance



假设我必须通过PHP对象进行MySQL查询,什么更好?或给该方法范围1000,并在一个呼叫中返回1000个记录?所有在速度/性能方面。

没有什么比少量练习

更好

如果您想玩一些乐趣,可以自己尝试:

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." msn";
print "Time to fetch 1000 records at once : ".$timeTwo." msn";

告诉我们结果;)

最新更新