dongmao3148 2013-05-02 17:29
浏览 55
已采纳

在OOP中调用函数是否很慢还是开销? [重复]

This question already has an answer here:

I am building an application which does some heavy repetition of functions.

For instance:

$Class = new Class;
for($i; $i < 1000; $i++) {
    $Class->get_something();
}

I have read so many articles on OOP and why it is slow, but I still don't understand where exactly the "slow" part is. People keep using the world "overhead," is that loading the actual class? Once I require a class, is it now the same speed when I call function or a variable?

</div>
  • 写回答

4条回答 默认 最新

  • doujiao3998 2013-05-02 17:34
    关注

    You are touching the very old debate between making a one large query to get your data, or looping over many smaller ones to receive them. And the answer lies in specifics of implementations. In some cases it is faster to call that one function over and over, while other times it will just kill your performance. The "overhead" from just calling a function over and over is pretty minimal, it's the "guts" of it that matter.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数