Created
December 1, 2014 13:56
-
-
Save zxytim/efd9f578a8aa9ef0aae9 to your computer and use it in GitHub Desktop.
a python-like decorator in coffee script
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
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