Skip to content

Instantly share code, notes, and snippets.

@garindra
Created November 24, 2011 02:45
Show Gist options
  • Save garindra/1390517 to your computer and use it in GitHub Desktop.
Save garindra/1390517 to your computer and use it in GitHub Desktop.
Simple benchmarker function
benchmark = (name, fn) ->
start = new Date().getTime()
fn()
delta = new Date().getTime() - start
console.log 'Benchmark "' + name + '" runs for ' + delta + ' ms.'
return delta
#example
benchmark 'string concat', ->
string = ""
for i in [0..10000]
string += "abcde"
#yields : 'Benchmark "string concat" runs for 24ms.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment