Skip to content

Instantly share code, notes, and snippets.

@boxed
boxed / timeIt.swift
Last active May 4, 2016 13:37 — forked from aschmied/timeIt.swift
Time code execution in Swift
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