Variable-length argument lists
JavaScript performance comparison
Info
Argument arrays vs. arguments object.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var updateUrl = 'UPDATE_URL',
issuesUrl = 'ISSUES_URL',
version = '1.2';
function makeTags(tagNames, helper) {
for (tag in tagNames) {
window[tagNames[tag]] = helper(tag);
}
}
function ns(string) {
return 'NAMESPACE' + string;
}
function argumentsTagHelper(name) {
return function(properties) {
var children = Array.prototype.slice.call(arguments, 1),
self = $('<' + name + '/>', properties);
$.each(children, function(_, child) {
if (child.jquery) {
self.append(child);
}
else {
self.html(child);
}
});
return self;
}
}
function arrayTagHelper(name) {
return function(properties, children) {
var self = $('<' + name + '/>', properties);
if (typeof children === 'string') {
self.html(children);
}
else if (children) {
$.each(children, function(_, child) {
self.append(child);
});
}
return self;
}
}
makeTags({a: 'a', br: 'br', div: 'div', input: 'input'}, argumentsTagHelper);
makeTags({a: 'a2', br: 'br2', div: 'div2', input: 'input2'}, arrayTagHelper);
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Varargs via arguments object |
|
pending… |
Varargs via args array |
|
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 Bulat
- Revision 2: published by Bulat
0 comments