什么被认为是长执行时间? [英] What is considered a long execution time?
问题描述
我想弄清楚我的服务器端代码的效率.
I am trying to figure out the efficiency of my server side code.
使用 microtime(true)
来测量速度,我可以计算我的脚本运行所用的时间.
Using microtime(true)
to measure speed, I am able to calculate the time it took my script to run.
我获得了 .3
到 .5
秒的平均速度.这些脚本执行大量数据库查询以向用户返回不同的值.
I am getting average speeds of .3
to .5
seconds. These scripts do a number of database queries to return different values to the user.
对于为网站在线运行的 PHP 脚本而言,什么时间被认为是有效的执行时间?
我知道这完全取决于正在执行的操作,但只需将其视为从数据库读取并将值返回给用户的标准脚本即可.我看着谷歌,看到他们在 .15
秒内搜索互联网,我觉得我的脚本很垃圾.
I know it depends on exactly what is being done, but just consider this a standard script that reads from a database and returns values to the user. I look at Google and see them search the internet in .15
seconds and I feel like my script is crap.
推荐答案
YouTube 的目标页面呈现时间为<100 毫秒(视频在这里 @7:00).
YouTube's target page rendering time is < 100ms (Video here @7:00).
您的瓶颈可能是数据库查询 - 尝试使用
Your bottleneck is probably DB queries - try using
EXPLAIN select * from x...
看看是否可以添加索引来加快查询速度.
to see if you can add indexes that will speed up your queries.
编辑上面的链接已经失效.高可扩展性在 YouTube 上做了一个功能,使用该视频作为其主要来源,所以它可能会引起一些兴趣:http://highscalability.com/youtube-architecture
edit the link above has died. High Scalability did a feature on YouTube that used that video as its primary source, so it may be of some interest: http://highscalability.com/youtube-architecture
这篇关于什么被认为是长执行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!