Skip to content

Instantly share code, notes, and snippets.

@Alexander-Ignition
Created September 17, 2018 06:40
Show Gist options
  • Save Alexander-Ignition/2f9b1620367dd9b399e36be56792becb to your computer and use it in GitHub Desktop.
Save Alexander-Ignition/2f9b1620367dd9b399e36be56792becb to your computer and use it in GitHub Desktop.
Measure on Darwin Match
func measure(_ name: String, _ block: () -> Void) {
let machToSeconds: Double = {
var timebase: mach_timebase_info_data_t = mach_timebase_info_data_t()
mach_timebase_info(&timebase)
return Double(timebase.numer) / Double(timebase.denom) * 1e-9
}()
let startTime = mach_absolute_time()
block()
let endTime = mach_absolute_time()
print(name, (machToSeconds * Double(endTime - startTime)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment