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条)

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写