Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support node 0.9, and give some human feedback

  • Loading branch information...
commit 31c1d1c31e62f25399f4f9d01d5ec743fad8fd7a 1 parent b8b6b17
@isaacs authored
Showing with 24 additions and 3 deletions.
  1. +24 −3 lib/bench.js
View
27 lib/bench.js
@@ -8,6 +8,15 @@ exports.compare = compare
exports.show = show
exports.runMain = runMain
+var nt_ = typeof setImmediate === 'function' ? setImmediate : process.nextTick
+var ntN = 0
+function nt(fn) {
+ if (ntN++ < 100)
+ return process.nextTick(fn)
+ nt_(fn)
+ ntN = 0
+}
+
function runMain () {
var test = require.main.exports
@@ -48,7 +57,7 @@ function run (fn, time, countPerLap, cb) {
function lap () {
runCount += countPerLap
if (Date.now() > stopTime) return done()
- process.nextTick(runner)
+ nt(runner)
}
function done () {
var did = runCount / (Date.now() - start)
@@ -91,13 +100,15 @@ function compare (set, compareCount, time, countPerLap, cb) {
comparerInner(i+1)
})
} else {
- process.nextTick(function () { comparer(currentCompare+1) })
+ nt(function () { comparer(currentCompare+1) })
}
})(0)
} else {
var ret = {}
for (var i = 0; i < testCount; i ++) {
- ret[ tests[i].name ] = results[i]
+ // throw out the first item in each list, since it's usually
+ // a vm warm-up anyway, and not a valid run.
+ ret[ tests[i].name ] = results[i].slice(1)
}
cb(null, ret)
}
@@ -153,6 +164,16 @@ function show (results) {
(pct(winner.avg, second.avg)+"% faster")
(times(winner.avg, second.avg)+" times as fast")
(oom(winner.avg, second.avg)+" order(s) of magnitude faster")
+
+ if (pct(winner.avg, second.avg) < 2) print
+ ("BASICALLY THE SAME")
+ else if (times(winner.avg, second.avg) < 2) print
+ ("A LITTLE FASTER")
+ else if (oom(winner.avg, second.avg) < 1) print
+ ("QUITE A BIT FASTER")
+ else print
+ ("A LOT FASTER")
+
if (loser) print
("\nCompared with the slowest ("+loser.name+"), it's:")
(pct(winner.avg, loser.avg)+"% faster")
Please sign in to comment.
Something went wrong with that request. Please try again.