Array push reverse vs. unshift reverse
JavaScript performance comparison
Info
Array push reverse vs. unshift reverse
See http://jsperf.com/forloop-vs-reverse-while-loop-and-array-reverse/9 for array reverse vs custom loops.
See http://jsperf.com/array-push-vs-unshift/6 for array push vs. unshift reversal.
Preparation code
<script>
Benchmark.prototype.setup = function() {
var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var length = array.length;
function reverse(array) {
var length = array.length;
var start = null;
var end = null;
for (start = 0; start < length / 2; start += 1) {
var temporary = array[start];
end = length - 1 - start;
array[start] = array[end];
array[end] = temporary;
}
return array;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
push |
|
pending… |
push reverse |
|
pending… |
unshift |
|
pending… |
unshift reverse |
|
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 XP1
- Revision 2: published
0 comments