How to create dispatch queue in Swift 3

前端 未结 15 2157
余生分开走
余生分开走 2020-11-22 16:35

In Swift 2, I was able to create queue with the following code:

let concurrentQueue = dispatch_queue_create(\"com.swift3.imageQueue\", DISPATCH_QUEUE_CONCURR         


        
15条回答
  •  猫巷女王i
    2020-11-22 17:37

    Since the OP question has already been answered above I just want to add some speed considerations:

    It makes a lot of difference what priority class you assign to your async function in DispatchQueue.global.

    I don't recommend running tasks with the .background thread priority especially on the iPhone X where the task seems to be allocated on the low power cores.

    Here is some real data from a computationally intensive function that reads from an XML file (with buffering) and performs data interpolation:

    Device name / .background / .utility / .default / .userInitiated / .userInteractive

    1. iPhone X: 18.7s / 6.3s / 1.8s / 1.8s / 1.8s
    2. iPhone 7: 4.6s / 3.1s / 3.0s / 2.8s / 2.6s
    3. iPhone 5s: 7.3s / 6.1s / 4.0s / 4.0s / 3.8s

    Note that the data set is not the same for all devices. It's the biggest on the iPhone X and the smallest on the iPhone 5s.

提交回复
热议问题