diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-19 17:10:27 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-19 17:10:27 -0700 |
commit | b31ab685bbd0b33e27cf65433ae10c7aa5df538e (patch) | |
tree | 68ed37f9dd19fbc9d8cc2079e5b64c29375ce081 | |
parent | 9a019d78fc2abb05496f4f39a2da9d628cd244c7 (diff) |
improve internal compiler Benchmarker
-rw-r--r-- | src/utility.js | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/utility.js b/src/utility.js index b793106c..9644b0e9 100644 --- a/src/utility.js +++ b/src/utility.js @@ -375,22 +375,28 @@ function ceilPowerOfTwo(x) { } function Benchmarker() { - var starts = {}, times = {}, counts = {}; + var totals = {}; + var ids = [], lastTime = 0; this.start = function(id) { - //printErr(['+', id, starts[id]]); - starts[id] = (starts[id] || []).concat([Date.now()]); + var now = Date.now(); + if (ids.length > 0) { + totals[ids[ids.length-1]] += now - lastTime; + } + lastTime = now; + ids.push(id); + totals[id] = totals[id] || 0; }; this.stop = function(id) { - //printErr(['-', id, starts[id]]); - assert(starts[id], new Error().stack); - times[id] = (times[id] || 0) + Date.now() - starts[id].pop(); - counts[id] = (counts[id] || 0) + 1; - this.print(); + var now = Date.now(); + assert(id === ids[ids.length-1]); + totals[id] += now - lastTime; + lastTime = now; + ids.pop(); }; - this.print = function() { - var ids = keys(times); - ids.sort(function(a, b) { return times[b] - times[a] }); - printErr('times: \n' + ids.map(function(id) { return id + ' : ' + counts[id] + ' times, ' + times[id] + ' ms' }).join('\n')); + this.print = function(text) { + var ids = keys(totals); + ids.sort(function(a, b) { return totals[b] - totals[a] }); + printErr(text + ' times: \n' + ids.map(function(id) { return id + ' : ' + totals[id] + ' ms' }).join('\n')); }; }; |