Last active
August 29, 2015 14:14
-
-
Save norio-nomura/399310ba93b730685888 to your computer and use it in GitHub Desktop.
Playgroundのテンプレートに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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swiftでクロージャの戻り値をジェネリックにしても、値を返さない(Void)にはマッチしないので、専用化が必要になる。