Converting arguments to an array
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var Array = window.Array;
var push = Array.prototype.push;
var slice = Array.prototype.slice;
var unshift = Array.prototype.unshift;
function arraySlice(array) {
return slice.call(array);
}
function arrayPush(array) {
var x = [];
push.apply(x, array);
return x;
}
function arrayUnshift(array) {
var x = [];
unshift.apply(x, array);
return x;
}
function whileLoop(array) {
var i = -1,
l = array.length,
x = Array(l);
while (++i < l) {
x[i] = array[i];
}
return x;
}
function byConstructor(array) {
return Array.apply(null, array);
}
var largeArray = Array(1001).join("a").split("");
var mediumArray = Array(101).join("a").split("");
var smallArray = Array(6).join("a").split("");
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Array#slice
|
|
pending… |
Array#push
|
|
pending… |
Array#unshift
|
|
pending… |
Array
|
|
pending… |
|
while loop
|
|
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.
- Revision 1: published
- Revision 2: published
- Revision 3: published
- Revision 4: published tj
- Revision 5: published
- Revision 6: published
- Revision 7: published damien maillard and last updated
- Revision 8: published rektide
- Revision 9: published
- Revision 11: published Charmander
- Revision 14: published
- Revision 16: published
- Revision 17: published private_face
- Revision 18: published
- Revision 19: published hooriza
- Revision 20: published
- Revision 21: published Calvin
- Revision 23: published
- Revision 25: published Benoit
- Revision 26: published
- Revision 27: published
- Revision 28: published
- Revision 29: published
- Revision 30: published
- Revision 32: published Niklas Lindgren
0 Comments