Contents

Develop
2021.09.14 06:05

[swift] 실행시간 측정하기

조회 수 3018 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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





?

  1. [ios] URL 랜딩 속도(OpenURL 10초 정지되는) 이슈

  2. [ios] iOS 8 개발자가 우선 알아야 할 3가지

  3. [ios] WWDC 2015 샘플 소스 코드 통합파일

  4. [ios] Touch ID 적용 샘플 코드 (예제)

  5. [ios] 문자열로 함수 실행하기 (eval 함수처럼)

  6. [ios] NSNotificationCenter 초간단 사용 예~ ㅋㄷ

  7. [ios] 새로 만들고 있는 DateMemo

  8. [ios] UIWebView에서 로컬에 있는 html 파일 불러오기

  9. 개인적으로 쓰고 있는 bash_profile

  10. [ios] SBCampanion App 초안

  11. [c] 이진 탐색 두 가지 코드 (재귀/반복)

  12. [ios] NSData to NSString (NSString to NSData)

Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99