Skip to content

Instantly share code, notes, and snippets.

@pfiller
Created May 12, 2014 16:43
Show Gist options
  • Save pfiller/4e4d6a25053303f0cc6d to your computer and use it in GitHub Desktop.
Save pfiller/4e4d6a25053303f0cc6d to your computer and use it in GitHub Desktop.
A console.time implementation in CoffeeScript
if window.console and typeof(window.console.time) is "undefined"
console.timeKey = (name) ->
return unless name
"KEY:" + name.toString()
console.time = (name, reset=false) ->
console.timeCounters ||= {}
return unless key = console.timeKey(name)
return if not reset and console.timeCounters[key]?
console.timeCounters[key] = new Date().getTime()
console.timeEnd = (name) ->
return unless key = console.timeKey(name)
if start = console.timeCounters?[key]
diff = new Date().getTime() - start
console.info "#{name}: #{diff}ms"
delete console.timeCounters[key]
return diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment