Contents

Develop
2021.09.14 06:05

[swift] 실행시간 측정하기

Views 680 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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





?

List of Articles
No. Category Subject Author Date Views
1173 Etc 원어민이 매일 쓰는 일상표현 150개 file hooni 2023.09.17 1104
1172 Etc 영어. 반드시 외워야 할 문장 패턴 100개 file hooni 2023.06.08 1122
1171 Develop [swift] UIView에서 subview 찾기 hooni 2022.12.09 1790
1170 System/OS 네트워크 용어 정리 file hooni 2022.11.20 1351
1169 System/OS [macos] How to Fix ‘You Shut Down Your Computer Because of a Problem’ file hooni 2022.06.01 794
1168 Develop [ios] 여러 버전의 Xcode 사용하기 hooni 2022.05.28 675
1167 Develop [ios] Pod 특정 버전 설치하고 사용하기 hooni 2022.05.28 1551
1166 System/OS 맥에서 포트 확인하고 닫기 (mac) hooni 2022.03.22 904
1165 System/OS 개인적으로 쓰고 있는 zshrc 파일 hooni 2022.02.25 835
1164 System/OS [apache2] Redirect HTTP to HTTPS file hooni 2022.02.03 691
1163 Develop macOS에 node, npm 설치하기 (homebrew) file hooni 2021.11.06 1149
1162 Develop [iOS] 시뮬레이터에 푸시 알림을 보내는 방법 file hooni 2021.10.13 1830
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98