Algorithm
[Swift] PS 시간 측정하기
thoonk:
2020. 11. 20. 20:35
반응형
swift언어로 문제를 풀다 보면 시간 초과가 뜨는 경우가 있어 시간 측정하는 방법을 기록합니다..
CFAbsoluteTimeGetCurrent()를 이용
import Foundation
processTime{
// Code
}
func processTime(closure: () -> ()){
let start = CFAbsoluteTimeGetCurrent()
closure()
let processTime = CFAbsoluteTimeGetCurrent() - start
print("경과 시간: \(processTime)")
}
출처
Measuring execution speed using CFAbsoluteTimeGetCurrent() - free Swift 5.1 example code and tips
Was this page useful? Let us know! 1 2 3 4 5
www.hackingwithswift.com
반응형