Extend function comparisons
JavaScript performance comparison
Info
Comparing jQuery and Underscore extend() functions for performance.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var targetObject,
extendingObject,
targetArray = [],
extendingArray = [];
// Populate Arrays.
for (var i = 0; i < 10000; i += 1) {
targetArray[i] = i;
extendingArray[i] = (i * 12) / 3;
}
targetObject = {
a: [],
b: {
one: "one",
two: {
point1: 2.1,
point2: 2.2,
point3: 2.3
},
three: [3.1, 3.2, 3.3, 3.4]
},
c: function(b) { b = 1; return b },
d: "okay",
e: 1
};
extendingObject = {
prop: function(){ return "prop"; },
d: targetArray,
f: function getE() { this.e = this.e * 1000; return this.e; }
};
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery.extend() |
|
pending… |
Underscore.extend() |
|
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 John Cockrell
- Revision 2: published by John Cockrell and last updated
- Revision 3: published by John Cockrell
- Revision 4: published by John Cockrell
- Revision 5: published by John Cockrell
- Revision 6: published by John Cockrell
0 comments