Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playgroundのテンプレートにbenchmark定義を入れてる。
import Foundation
import QuartzCore
func benchmark<T>(block: () -> T) -> String {
let measure = {(begin: CFTimeInterval) -> CFTimeInterval in block(); return CACurrentMediaTime() - begin}
let result = String(format: "Total Runtime: %g sec", measure(CACurrentMediaTime()))
println(result)
return result
}
func benchmark(block: () -> ()) -> String {
let measure = {(begin: CFTimeInterval) -> CFTimeInterval in block(); return CACurrentMediaTime() - begin}
let result = String(format: "Total Runtime: %g sec", measure(CACurrentMediaTime()))
println(result)
return result
}
// MARK: -
benchmark {
// write code here
}
@norio-nomura
Copy link
Author

norio-nomura commented Feb 2, 2015

Swiftでクロージャの戻り値をジェネリックにしても、値を返さない(Void)にはマッチしないので、専用化が必要になる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment