NSNotificationCenter 与委托 - 哪个更快?

NSNotificationCenter vs delegation - which is faster?(NSNotificationCenter 与委托 - 哪个更快?)
本文介绍了NSNotificationCenter 与委托 - 哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于每种方法的优缺点的信息,并且我知道代表通常是针对一个听众的,而通知是针对许多听众的.问题是关于性能的.

I have read a lot about the pros and cons of each , and i know delegates are usually for one listener, and notifications are for many. The question is about performance.

我已阅读:NSNotificationCenter 与委派(使用协议)?

我正在通过通知从麦克风向另一个班级发送音频信号.我知道我应该在这里使用委托,但我的问题是:委托会更快吗?因为我可以看到我有一些帧速率问题(降低),我想知道原因是否可能是使用通知而不是委托,或者没有关系?

I am sending audio signals from mic, to another class by notification . i know that here i should use the delegate BUT my question is : does delegates will be faster ? because i can see i have some frame rate issue(decreased), and i would like to know if the cause could be the using of notification instead of delegate, or there is no relation ?

推荐答案

委托的开销更少,因此执行速度更快.

Delegates come with less overhead and will therefore be executed much faster.

但是,一般来说,您应该只在可能成为问题的地方查看性能主题.对于像发送通知和调用委托这样的一次性任务,这永远不会成为问题.但是,当您计划在循环中使用变量(取决于数据)执行这些操作时,或者对于您已获取或接收数据的许多数据对象,无法预测会有多少 - 这些情况是我会考虑性能优化.

However, in general you should look on performance topics only there where they are likely to be an issue at all. For once-off tasks like sending a notification vs calling a delegate this should never be an issue. But when you plan to perform these in a loop with a variable (depending on data) number of intarations or for a number of data objects where you have fetched or received the data an cannot predict how many there will be - those are the situations where I would consider performance optimization.

这篇关于NSNotificationCenter 与委托 - 哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
appearance().setBackgroundImage Not Working On Custom Class(外观().setBackoundImage在自定义类上不起作用)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
Show/Hide barButtonItem(显示/隐藏barButtonItem)