Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let date_start = NSDate()
- // Code to be executed
- println("(-date_start.timeIntervalSinceNow)")
- func testExample() {
- self.measureBlock() {
- //do something you want to measure
- }
- }
- func printTimeElapsedWhenRunningCode(title:String, operation:()->()) {
- let startTime = CFAbsoluteTimeGetCurrent()
- operation()
- let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
- println("Time elapsed for (title): (timeElapsed) s.")
- }
- func timeElapsedInSecondsWhenRunningCode(operation: ()->()) -> Double {
- let startTime = CFAbsoluteTimeGetCurrent()
- operation()
- let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
- return Double(timeElapsed)
- }
- printTimeElapsedWhenRunningCode(title:"map()") {
- let resultArray1 = randoms.map { pow(sin(CGFloat($0)), 10.0) }
- }
- import Foundation
- func measure(_ title: String, block: (() -> ()) -> ()) {
- let startTime = CFAbsoluteTimeGetCurrent()
- block {
- let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
- print("(title):: Time: (timeElapsed)")
- }
- }
- measure("some title") { finish in
- myAsyncCall {
- finish()
- }
- // ...
- }
- measure("some title") { finish in
- // code to benchmark
- finish()
- // ...
- }
Add Comment
Please, Sign In to add comment