[swift] 실행시간 측정하기
start, end 구해서 end-start
func evaluateProblem(problemNumber: Int, problemBlock: () -> Int) -> Answer
{
print("Evaluating problem \(problemNumber)")
let start = DispatchTime.now() // <<<<< Start time
let myGuess = problemBlock()
let end = DispatchTime.now() // <<<<< End time
let theAnswer = self.checkAnswer(answerNum: "\(problemNumber)", guess: myGuess)
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds // <<<<< Difference in nano seconds (UInt64)
let timeInterval = Double(nanoTime) / 1_000_000_000 // Technically could overflow for long running test
print("Time to evaluate problem \(problemNumber): \(timeInterval) seconds")
return theAnswer
}
출처: https://stackoverflow.com/questions/24755558/measure-elapsed-time-in-swift
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1171 | Develop | [swift] UIView에서 subview 찾기 | hooni | 2022.12.09 | 327 |
1170 | System/OS |
네트워크 용어 정리
![]() |
hooni | 2022.11.20 | 248 |
1169 | System/OS |
[macos] How to Fix ‘You Shut Down Your Computer Because of a Problem’
![]() |
hooni | 2022.06.01 | 465 |
1168 | Develop | [ios] 여러 버전의 Xcode 사용하기 | hooni | 2022.05.28 | 423 |
1167 | Develop | [ios] Pod 특정 버전 설치하고 사용하기 | hooni | 2022.05.28 | 399 |
1166 | System/OS | 맥에서 포트 확인하고 닫기 (mac) | hooni | 2022.03.22 | 620 |
1165 | System/OS | 개인적으로 쓰고 있는 zshrc 파일 | hooni | 2022.02.25 | 353 |
1164 | System/OS |
[apache2] Redirect HTTP to HTTPS
![]() |
hooni | 2022.02.03 | 365 |
1163 | Develop |
macOS에 node, npm 설치하기 (homebrew)
![]() |
hooni | 2021.11.06 | 551 |
1162 | Develop |
[iOS] 시뮬레이터에 푸시 알림을 보내는 방법
![]() |
hooni | 2021.10.13 | 1095 |
1161 | Develop | [iOS] Xcode 불필요한 캐시 삭제하기 | hooni | 2021.10.12 | 818 |
» | Develop | [swift] 실행시간 측정하기 | hooni | 2021.09.14 | 437 |