GCD与自定义队列 [英] GCD vs custom queue

查看:123
本文介绍了GCD与自定义队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这两者之间在性能上有什么区别.

I was wondering what is the difference in performance between these two.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

    // perform complex operation

    // dispatch back to main thread to update UI

});



dispatch_async(_myCustomConcurrentQueue, ^{

    // perform complex operation

    // dispatch back to main thread to update UI

});

我的假设是GCD在操作系统和其他应用程序中使用,它将需要执行非常快速的后台任务并快速完成.创建的自定义队列与GCD是分开的,它们可以运行不同的任务,一旦释放,它们将被添加回池中.因此,我的假设是,对于复杂的操作,我的customQueue的性能要优于GCD.

My assumption is the GCD is used across the os and other applications, and it will need to perform very quick background tasks, and be finished quick. And custom queues that are created are separate from GCD and they can run a different task, and will be added back to the pool once they are released. And so my assumption is that my customQueue performs better than GCD for a complex operation.

您有什么想法?哪个表现更好?他们是一样的吗?

What are your thoughts? Which performs better? Are they the same?

推荐答案

虽然高优先级全局队列理论上可能更快(因为您不必创建队列,线程优先级稍有不同),但两者之间的区别并且您自己的自定义并发队列不太可能被观察到.但是,您可能有两个原因要使用自己的自定义队列:

While the high-priority global queue might theoretically be faster (since you don't have to create the queue, slightly different thread priority), the difference between that and your own custom concurrent queue is unlikely to be observable. There are two reasons, though, that you might want to use your own custom queues:

  1. 某些功能(尤其是分派屏障)在全局队列中不可用,因此,如果需要这些功能,则需要使用自定义队列.

  1. Certain features, notably dispatch barriers, are unavailable in global queues, so if you need those features, you'll want to use custom queue.

调试应用程序,使用自己的有意义名称的队列也很有用,这样您可以更轻松地在调试器中标识各个线程.

Debugging your app, it can also be useful to use your own queues with meaningful names, so that you can more easily identify the individual threads in the debugger.

但是选择高优先级的全局并发队列与自定义并发队列并没有实质性的性能原因.

But there are no material performance reasons to choose high priority global concurrent queue vs a custom concurrent queue.

这篇关于GCD与自定义队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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