NSNotificationCenter与授权 - 哪个更快? [英] NSNotificationCenter vs delegation - which is faster?

查看:121
本文介绍了NSNotificationCenter与授权 - 哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读了很多关于每个人的利弊,我知道代表通常是一个听众,通知是为许多。问题在于性能问题。



我已阅读: NSNotificationCenter vs委托(使用协议)?



我通过通知将麦克风的音频信号发送到另一个类。我知道在这里我应该使用代理,但我的问题是:代表会更快吗?因为我可以看到我有一些帧速率问题(减少),而且我想知道是否可以使用代理的通知,或者没有关系?

解决方案

代表们的开销较少,因此执行速度更快。



但是,一般来说,您应该仅在性能主题上看到它们可能是一个问题。对于一次性的任务,如发送通知,而不是调用委托这不应该是一个问题。但是,当您计划使用变量(取决于数据)的数量或者已经获取或接收到数据的多个数据对象的循环执行这些操作时,无法预测将会有多少 - 这些情况是我会考虑性能优化。


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.

I have read this : NSNotificationCenter vs delegation( using protocols )?

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与授权 - 哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆