Skip to content

Instantly share code, notes, and snippets.

@alun
Created August 26, 2014 07:55
Show Gist options
  • Save alun/db604ae322624ca45924 to your computer and use it in GitHub Desktop.
Save alun/db604ae322624ca45924 to your computer and use it in GitHub Desktop.
Script timings
try
Array::sum = ->
sum = 0
for x in @
sum += x
sum
now = -> new Date().getTime()
time = (f, takes = 100000) ->
start = now()
total = 0
for i in [1..takes]
f()
total += now() - start
start = now()
repeat f, takes
total / takes
calc = -> [1..1].sum()
console.log time ->
# f = -> calc()
# f()
calc()
, 100000
catch e
console.log e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment