Assuming I have this kind of function and DispatchQueue logic. Assume that when synchLatest()
gets called it fires "Code Block 1"
twice.
How is supposed to be that, during a loop, the execution of "Code Block 1"
which is only a retrieve of a string from the grpc response and a store in UserDefaults take me 1.7 seconds
and the second it gets executed during the loop it takes 5 seconds
?
let synchQueue = DispatchQueue(label: "com.dmapp.synchQueue", qos: .default, attributes: .concurrent)
let synchProcessQueue = DispatchQueue(label: "com.dmapp.processQueue", qos: .default, attributes: .concurrent)
func synchLatest() {
while(someconditions) {
synchQueue.async {
...
let response = try grpcCall.receive()
...
synchProcessQueue.async {
....
measure("Code Block 1", {
if response.data.nickname != "" {
// Store in UserDefaults
}
})
....
}
}
}
}
@discardableResult
static func measure<A>(name: String = "", _ block: () -> A) -> A {
let startTime = CACurrentMediaTime()
let result = block()
let timeElapsed = CACurrentMediaTime() - startTime
print("Time: \(name) - \(timeElapsed)")
return result
}
Am I measuring code execution time here in the wrong way?