Created
January 8, 2024 12:44
-
-
Save sabapathyk7/fba6d197225202efeb6a26f138414d6a to your computer and use it in GitHub Desktop.
Basics of QoS - Swift - GCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
extension Date { | |
var currentTimeStamp: Int64 { | |
Int64(self.timeIntervalSince1970 * 1000) | |
} | |
} | |
func concurrency() { | |
print("background start Time: \(Date().currentTimeStamp) ") | |
DispatchQueue.global(qos: .background).async { | |
for i in 1...3{ | |
sleep(3) | |
print("background Counter:\(i), time \(Date().currentTimeStamp) ") | |
} | |
} | |
print("UserInitiated start Time: \(Date().currentTimeStamp) ") | |
DispatchQueue.global(qos: .userInitiated).async { | |
for i in 1...3{ | |
sleep(3) | |
print("UserInitiated Counter:\(i), time \(Date().currentTimeStamp) ") | |
} | |
} | |
print("Utility start Time: \(Date().currentTimeStamp) ") | |
DispatchQueue.global(qos: .utility).async { | |
for i in 1...3{ | |
sleep(3) | |
print("Utility Counter:\(i), time \(Date().currentTimeStamp) ") | |
} | |
} | |
print("UserInteractive start Time: \(Date().currentTimeStamp) ") | |
DispatchQueue.global(qos: .userInteractive).async { | |
for i in 1...3{ | |
sleep(3) | |
print("UserInteractive Counter:\(i), time \(Date().currentTimeStamp) ") | |
} | |
} | |
print("Default start Time: \(Date().currentTimeStamp) ") | |
DispatchQueue.global(qos: .default).async { | |
for i in 1...3{ | |
sleep(3) | |
print("Default Counter:\(i), time \(Date().currentTimeStamp) ") | |
} | |
} | |
} | |
concurrency() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment