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
import CoreFoundation | |
func timeIt(m: () -> ()) -> (Double, Int) { | |
let startTime = CFAbsoluteTimeGetCurrent() | |
var numberOfRuns = 0 | |
while true { | |
m() | |
numberOfRuns += 1 | |
let elapsed = CFAbsoluteTimeGetCurrent() - startTime | |
if elapsed > 0.5 { // we run the function up to 0.5 seconds, assuming here that we want to sample functions that are pretty fast |