Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created January 11, 2012 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmoran/1592316 to your computer and use it in GitHub Desktop.
Save jrmoran/1592316 to your computer and use it in GitHub Desktop.
timeIt = (f)->
start = Date.now()
f()
console.log 'time: ', Date.now() - start, 'ms'
adder = ->
total = 0
((n = 0)-> total += n)
timeIt ->
add = adder()
add n for n in [0..1e6]
console.log 'adder result:', add()
# Output
#
# adder result: 500000500000
# time: 39 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment