Contents

Develop
2021.09.14 06:05

[swift] 실행시간 측정하기

조회 수 3043 댓글 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





?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
409 Develop [js]모바일 웹에서 orientationchange hooni 2013.04.23 20858
408 Develop [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보 hooni 2020.12.15 2818
407 Develop [lego] 세그웨이 이것만 볼것.. ㅎㅎ file hooni 2013.04.23 36852
406 Etc [link] iOS(아이폰) 개발 관련 ㅋㅋ hooni 2013.04.23 22635
405 Etc [link] 유용한 사이트 링크. hooni 2013.08.19 131288
404 System/OS [linux] /etc/fstab 설정 방법.. ㅋㅋ hooni 2013.04.23 13138
403 System/OS [linux] apache, php, jsp 환경설정하기.. hooni 2003.04.23 16156
402 System/OS [linux] APM(apache, php, mysql) + gd 설치순서.. hooni 2003.04.23 20076
401 System/OS [linux] awk 명령어 hooni 2014.03.11 6005
400 System/OS [linux] CentOS 6.5 에서 "Bringing up interface eth0: Determining if ip address 121.78.127.197 is already in use for device eth0..." hooni 2014.04.05 7353
399 System/OS [linux] CentOS 6.x Cati 설치 (yum) hooni 2014.01.17 49680
398 System/OS [linux] CentOS Apache Httpd에 https 적용 hooni 2014.03.05 5338
Board Pagination Prev 1 ... 60 61 62 63 64 65 66 67 68 69 ... 99 Next
/ 99