Created
December 11, 2018 07:29
-
-
Save edwardean/5eff55625a62f053d7bf0094006d4ec5 to your computer and use it in GitHub Desktop.
Swift方法执行耗时测量
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func measure(block: () -> Void) -> Double { | |
let start = DispatchTime.now() | |
block() | |
let end = DispatchTime.now() | |
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds // <<<<< Difference in nano seconds (UInt64) | |
let timeInterval = Double(nanoTime) / 1_000_000_000 | |
return timeInterval | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment