From 8e204166753502457c8ea180926849bba070c16b Mon Sep 17 00:00:00 2001 From: Pauan Date: Sun, 31 May 2015 03:14:03 -1000 Subject: [PATCH 1/2] Adding in rudimentary benchmark system --- benchmarks/benchmarks.js | 4 ++++ benchmarks/drain.js | 15 +++++++++++++++ benchmarks/scaffold.js | 32 ++++++++++++++++++++++++++++++++ package.json | 3 ++- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 benchmarks/benchmarks.js create mode 100644 benchmarks/drain.js create mode 100644 benchmarks/scaffold.js diff --git a/benchmarks/benchmarks.js b/benchmarks/benchmarks.js new file mode 100644 index 0000000..b85ee78 --- /dev/null +++ b/benchmarks/benchmarks.js @@ -0,0 +1,4 @@ +var drain = require("./drain"); +var benchmark = require("./scaffold"); + +benchmark.run(); 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/scaffold.js b/benchmarks/scaffold.js new file mode 100644 index 0000000..2f1368d --- /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 add_timer(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 () {}); + + add_timer(s, f); +} + +function run() { + suite.run(); +} + +exports.time = time; +exports.run = run; diff --git a/package.json b/package.json index cbbc063..b3cf17c 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,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" } } From 30d77b162a3fc13e304d3e3beb50fdb5d6ada175 Mon Sep 17 00:00:00 2001 From: Pauan Date: Sun, 31 May 2015 22:48:37 -1000 Subject: [PATCH 2/2] Fixing issues --- benchmarks/{benchmarks.js => index.js} | 0 benchmarks/scaffold.js | 4 ++-- package.json | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) rename benchmarks/{benchmarks.js => index.js} (100%) diff --git a/benchmarks/benchmarks.js b/benchmarks/index.js similarity index 100% rename from benchmarks/benchmarks.js rename to benchmarks/index.js diff --git a/benchmarks/scaffold.js b/benchmarks/scaffold.js index 2f1368d..df6b698 100644 --- a/benchmarks/scaffold.js +++ b/benchmarks/scaffold.js @@ -6,7 +6,7 @@ var suite = new Benchmark.Suite({ } }); -function add_timer(s, f) { +function addTimer(s, f) { suite.add(s, function (deferred) { f(function () { deferred.resolve(); @@ -21,7 +21,7 @@ function time(s, f) { // have any errors before benchmarking it f(function () {}); - add_timer(s, f); + addTimer(s, f); } function run() { diff --git a/package.json b/package.json index b3cf17c..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",