compare when/function.apply implementations
JavaScript performance comparison
Preparation code
<script src="https://raw.github.com/cujojs/when/1.8.0/when.js"></script>
<script>
Benchmark.prototype.setup = function() {
var sum = function(a, b) {
return a + b;
};
var testCases = [
[10, 20],
when.resolve([10, 20]),
[when.resolve(10), when.resolve(20)],
when.resolve([when.resolve(10), when.resolve(20)])
];
function assertResult(result) {
if(result != 30) {
throw new Error("Wrong result! " + result);
}
};
function executeTestCases(implem) {
testCases.forEach(function(testCase) {
implem(sum, testCase).then(assertResult).otherwise(function(reason) {
console.error(reason);
});
});
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
With 'then' |
|
pending… |
Without 'then' |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Renato Zannon
- Revision 2: published by Renato Zannon
0 comments