Created
October 14, 2016 15:59
-
-
Save heyalexchoi/e7475eec3b043086c9a8507c37c80011 to your computer and use it in GitHub Desktop.
swift benchmarker
This file contains hidden or 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
/*! accepts event names and prints out time interval (seconds) since last event given */ | |
struct Benchmarker { | |
struct Event { | |
let time: NSDate | |
let name: String | |
} | |
static var events = [Event]() | |
static let prefix = "--------\n--------\n--------\nBENCHMARK\n--------\n--------\n--------\n" | |
static func benchmark(eventName: String) { | |
let event = Event(time: NSDate(), name: eventName) | |
if let last = events.last { | |
debugPrint("\(prefix)\(event.name)! \(event.time.timeIntervalSinceDate(last.time)) seconds since \(last.name)") | |
} else { | |
debugPrint("\(prefix)\(event.name)!") | |
} | |
events.append(event) | |
} | |
static func clear() { | |
events = [Event]() | |
} | |
static func complete(eventName: String) { | |
benchmark(eventName) | |
clear() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment