Convert arguments into an Array
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var convert = function(obj) {
if (!(obj.length >= 0)) { // undefined or < 0
return null;
}
var i,a = [], len = obj.length;
for (i=0; i<len; i++) {
a.push(obj[i]);
}
return a;
},
f1 = function() {return convert(arguments);},
f2 = function() {return [].slice.apply(arguments);},
f3 = function() {return Array.prototype.slice.apply(arguments);};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Laborious way |
|
pending… |
Slice 1 |
|
pending… |
Slice 2 |
|
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 Baptiste Fontaine
- Revision 2: published
0 comments