Skip to content

Instantly share code, notes, and snippets.

@V8tr
Last active January 20, 2021 12:07
Show Gist options
  • Save V8tr/e030176b09db21cf9578ebbec8e1f0e6 to your computer and use it in GitHub Desktop.
Save V8tr/e030176b09db21cf9578ebbec8e1f0e6 to your computer and use it in GitHub Desktop.
Benchmark arbitrary block of code in Swift. See blog post for more details: http://www.vadimbulavin.com/benchmarking-locking-apis/
func benchmark(block: () -> Void) -> TimeInterval {
let startTime = CFAbsoluteTimeGetCurrent()
block()
let endTime = CFAbsoluteTimeGetCurrent()
let totalTime = endTime - startTime
return totalTime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment