Suppose we have the following code defining a continuous loop (as in for a game):
let queue = DispatchQueue(label: "DemoSerialQueue")
let workItem = DispatchWorkItem{ print("Hello World") }
func gameLoop() {
queue.async(execute:workItem)
}
Would the above code be more efficient in terms of speed than the following:
func gameLoop() {
queue.async{ print("Hello World") }
}
In particular I'm wondering if the second form would be allocating a closure on every loop and thus incuring a performance hit.