diff --git a/benchmarks/drain.js b/benchmarks/drain.js new file mode 100644 index 0000000..37af515 --- /dev/null +++ b/benchmarks/drain.js @@ -0,0 +1,15 @@ +var benchmark = require("./scaffold"); +var asap = require("../asap"); + +benchmark.time("Drain", function (done) { + var pending = 100; + + for (var i = 0; i < 100; ++i) { + asap(function () { + --pending; + if (pending === 0) { + done(); + } + }); + } +}); diff --git a/benchmarks/index.js b/benchmarks/index.js new file mode 100644 index 0000000..b85ee78 --- /dev/null +++ b/benchmarks/index.js @@ -0,0 +1,4 @@ +var drain = require("./drain"); +var benchmark = require("./scaffold"); + +benchmark.run(); diff --git a/benchmarks/scaffold.js b/benchmarks/scaffold.js new file mode 100644 index 0000000..df6b698 --- /dev/null +++ b/benchmarks/scaffold.js @@ -0,0 +1,32 @@ +var Benchmark = require("benchmark"); + +var suite = new Benchmark.Suite({ + onCycle: function (event) { + console.log("" + event.target); + } +}); + +function addTimer(s, f) { + suite.add(s, function (deferred) { + f(function () { + deferred.resolve(); + }); + }, { + defer: true + }); +} + +function time(s, f) { + // This is to make sure that the function doesn't + // have any errors before benchmarking it + f(function () {}); + + addTimer(s, f); +} + +function run() { + suite.run(); +} + +exports.time = time; +exports.run = run; diff --git a/package.json b/package.json index cbbc063..a62f324 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "test-saucelabs-all": "node scripts/saucelabs.js test/asap-test.js scripts/saucelabs-all-configurations.json", "test-saucelabs-worker": "node scripts/saucelabs-worker-test.js scripts/saucelabs-spot-configurations.json", "test-saucelabs-worker-all": "node scripts/saucelabs-worker-test.js scripts/saucelabs-all-configurations.json", - "lint": "jshint raw.js asap.js browser-raw.js browser-asap.js $(find scripts -name '*.js' | grep -v gauntlet)" + "lint": "jshint raw.js asap.js browser-raw.js browser-asap.js $(find scripts -name '*.js' | grep -v gauntlet)", + "benchmarks": "node benchmarks" }, "devDependencies": { "events": "^1.0.1", @@ -49,6 +50,7 @@ "q-io": "^2.0.3", "saucelabs": "^0.1.1", "wd": "^0.2.21", - "weak-map": "^1.0.5" + "weak-map": "^1.0.5", + "benchmark": "^1.0.0" } }