我已经阅读了很多关于每种方法的优缺点的信息,并且我知道代表通常是针对一个听众的,而通知是针对许多听众的.问题是关于性能的.
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 与委托 - 哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!