Skip to content

Instantly share code, notes, and snippets.

@edwardean
Created December 11, 2018 07:29
Show Gist options
  • Save edwardean/5eff55625a62f053d7bf0094006d4ec5 to your computer and use it in GitHub Desktop.
Save edwardean/5eff55625a62f053d7bf0094006d4ec5 to your computer and use it in GitHub Desktop.
Swift方法执行耗时测量
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