首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Php/MySQL性能

Php/MySQL性能
EN

Stack Overflow用户
提问于 2014-02-02 00:13:13
回答 1查看 98关注 0票数 1

假设我必须通过php对象执行MySQL查询,那么有什么更好的方法呢?让方法明确地返回一条记录并调用此方法--让其调用1000次(更改参数),或者在一次调用中给该方法1000的范围,并返回1000条记录?都是在速度/性能方面。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-02 01:47:05

没有什么比小小的锻炼更好的了

如果你想找点乐子,你可以自己试试:

代码语言:javascript
复制
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";

告诉我们结果;)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21505433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档