perf impact of passing references
JavaScript performance comparison
Info
This test is attempting to show the performance impact of passing references compared to normal scope chain lookups.
Check out Compact.js, that's based on Require.js
Dominik Guzei Wizzart by the way -> I'm searching for a JavaScript internship :)
Modified By
Preparation code
<script>
ui.benchmarks[0].setup = function() {
var Library = {
'util': {
'add': function(a, b) {
return a + b;
}
},
'cool': {
'Class': function(startValue) {
this.value = startValue;
}
}
};
Library.cool.Class.prototype = {
'addToValue': function(value) {
this.value = Library.util.add(this.value, value);
}
};
};
ui.benchmarks[1].setup = function() {
var cache = {};
function define(namespace, includes, callback) {
var i = -1;
if (arguments.length < 3) {
callback = includes;
includes = [];
}
// convert string namespaces to objects
while (includes[++i]) {
includes[i] = cache[includes[i]];
}
cache[namespace] = callback.apply(null, includes);
}
function require(includes, callback) {
var i = -1;
// convert string namespaces to objects
while (includes[++i]) {
includes[i] = cache[includes[i]];
}
callback.apply(null, includes);
}
define('Library.util.add', function() {
function add(a, b) {
return a + b;
}
return add;
});
define('Library.cool.Class', ['Library.util.add'], function(add) {
function Class(startValue) {
this.value = startValue;
}
Class.prototype = {
'addToValue': function(value) {
this.value = add(this.value, value);
}
};
return Class;
});
var Klass;
require(['Library.cool.Class'], function(Class) {
Klass = Class;
});
};
ui.benchmarks[2].setup = ui.benchmarks[1].setup;
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Normal Lookup |
|
pending… |
Local Lookup |
|
pending… |
Passing+Require |
|
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 Dominik Guzei and last updated
- Revision 2: published by Micheil Smith
- Revision 3: published by eric
- Revision 4: published by dnolen
- Revision 5: published by dnolen
- Revision 6: published by Jie
- Revision 7: published by Tom Schuster
- Revision 9: published by eric
- Revision 10: published by eric
- Revision 11: published by Dominik Guzei
- Revision 12: published and last updated
0 comments