Created
August 11, 2014 18:14
-
-
Save kongtomorrow/b7830e039e1618456281 to your computer and use it in GitHub Desktop.
benchmark
This file contains 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 benchmark<T>(label:String, body:()->T) { | |
var info = mach_timebase_info_data_t(numer: 0, denom: 0) | |
mach_timebase_info(&info) | |
let tick = mach_absolute_time() | |
let res = body() | |
let tock = mach_absolute_time() | |
let delta = tock - tick | |
let nanos = delta * UInt64(info.numer) / UInt64(info.denom) | |
let seconds = Double(nanos) / Double(NSEC_PER_SEC) | |
"\(label) returned \(res) in \(seconds) seconds"*** | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment