Skip to content

Instantly share code, notes, and snippets.

@zxytim
Created December 1, 2014 13:56
Show Gist options
  • Save zxytim/efd9f578a8aa9ef0aae9 to your computer and use it in GitHub Desktop.
Save zxytim/efd9f578a8aa9ef0aae9 to your computer and use it in GitHub Desktop.
a python-like decorator in coffee script
timing = (msg) -> (method) -> ->
startTime = (new Date()).getTime()
ret = method.apply @, arguments
duration = (new Date()).getTime() - startTime
msg = if msg then msg else ''
console.log '[timing] ' + msg + ': ' + duration / 1000.0
ret
consumeTime = timing('hello') ->
s = 0
for i in [0..100000000]
s += 1
s
console.log consumeTime()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment