Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created June 9, 2015 21:58
Show Gist options
  • Save loganwright/cad0efca6ab542bf8693 to your computer and use it in GitHub Desktop.
Save loganwright/cad0efca6ab542bf8693 to your computer and use it in GitHub Desktop.
Timer struct for running very simple, and imprecise measuring of operations

#Timer

struct Timer : Printable {
    let start = NSDate()
    let name: String
    var description: String {
        let now = NSDate()
        let dif = now.timeIntervalSince1970 - start.timeIntervalSince1970
        let roundedDif =  Double(round(1000 * dif)/1000)
        return "\(name) : \(roundedDif)"
    }
}

#Usage

let timer = Timer(name: "Some Thing I'm Timing")

// Do stuff I'm curious about.

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