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
1077 Develop [Xcode] 디버깅 옵션 file hooni 2013.04.23 57200
1076 Develop [winmobile] 윈도우 모바일 간단한 테스트 코드 ㅋㅋ file hooni 2013.04.23 17086
1075 System/OS [windows] 패스워드를 잊어먹었을때.. hooni 2003.04.23 17296
1074 System/OS [windows] 최근 열어본 문서목록 안나오게 하는 방법 hooni 2013.04.23 25485
1073 System/OS [windows] 종료, 재시작, 로그아웃 아이콘 만들기 hooni 2013.04.23 18103
1072 System/OS [windows] 인터넷 익스플로러(IE) 도구모음 표시줄에 아이콘 추가 file hooni 2013.04.23 18219
1071 System/OS [windows] 윈도우즈 콘솔에서 정품인증 하는 방법 hooni 2017.05.24 5360
1070 System/OS [windows] 윈도우 사용자 계정 로그인 암호 분실, 암호 변경하는 방법 file hooni 2015.07.09 21374
1069 System/OS [windows] 원격 데스크탑(터미널 서비스) 포트 변경 hooni 2013.04.23 16305
1068 System/OS [windows] 여러가지 활용 팁 hooni 2003.04.23 19977
1067 System/OS [windows] 배치(bat)파일 제작 방법 hooni 2003.04.23 17010
1066 System/OS [windows] 도스 사용 팁 hooni 2003.04.23 17814
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 98 Next
/ 98