Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding in rudimentary benchmark system #60

Merged
merged 2 commits into from
Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions benchmarks/drain.js
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
});
4 changes: 4 additions & 0 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var drain = require("./drain");
var benchmark = require("./scaffold");

benchmark.run();
32 changes: 32 additions & 0 deletions benchmarks/scaffold.js
Original file line number Diff line number Diff line change
@@ -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 () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should add a rule to the linter for named functions.

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;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a "scripts.benchmarks": "node benchmarks" so we can do npm run benchmarks

}
}