1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

"cake bench" now shows total time spent

This commit is contained in:
satyr 2010-11-18 21:33:56 +09:00
parent 1a9a48c5f2
commit bcbf9f7dfd

View file

@ -124,17 +124,19 @@ task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', ->
task 'bench', 'quick benchmark of compilation time', ->
{Rewriter} = require './lib/rewriter'
co = sources.map((name) -> fs.readFileSync name).join '\n'
fmt = (ms) -> " : #{bold}#{ " #{ms}".slice -4 }#{reset}[ms]"
total = 0
now = Date.now()
time = ->
bold + (' ' + -(now - now = Date.now())).slice(-5) + reset + '[ms]'
time = -> total += ms = -(now - now = Date.now()); fmt ms
tokens = CoffeeScript.tokens co, rewrite: false
console.log "Lex :#{time()} (#{tokens.length} tokens)"
console.log "Lex #{time()} (#{tokens.length} tokens)"
tokens = new Rewriter().rewrite tokens
console.log "Rewrite :#{time()} (#{tokens.length} tokens)"
console.log "Rewrite#{time()} (#{tokens.length} tokens)"
nodes = CoffeeScript.nodes tokens
console.log "Parse :#{time()}"
console.log "Parse #{time()}"
js = nodes.compile bare: true
console.log "Compile :#{time()} (#{js.length} bytes)"
console.log "Compile#{time()} (#{js.length} chars)"
console.log "TOTAL #{ fmt total }"
task 'loc', 'count the lines of source code in the CoffeeScript compiler', ->
exec "cat #{ sources.join(' ') } | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) ->