Skip to content

Instantly share code, notes, and snippets.

@artemnovichkov
Created January 23, 2017 03:46
Show Gist options
  • Save artemnovichkov/def8b4e51d7780eac2abbd4a4ff40272 to your computer and use it in GitHub Desktop.
Save artemnovichkov/def8b4e51d7780eac2abbd4a4ff40272 to your computer and use it in GitHub Desktop.
Function for check algorithm efficiency
func benchmark(repeatCount: Int = 1, name: String? = nil, closure: () -> Void) {
let d = CACurrentMediaTime()
for _ in 0..<repeatCount {
closure()
}
let d1 = CACurrentMediaTime() - d
print("Benchmark of \(name ?? "closure") took \(d1) seconds")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment