Speed of Array shift vs. pop (v14)

Revision 14 of this benchmark created by 1024-- on


Description

Which is faster, working from the front or the back, or are they equivalent?

Preparation HTML

<script>
window.r = 0;
setInterval(function(){ console.log(window.r); }, 1000);
</script>

Setup

window.a = [];
    var i, result = 0;
    for (i = 1000; i >= 0; i--) {
        a[i] = i;
    }

Teardown


    window.r += result;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Speed of shift
while (test = a.shift()) {
  result += test;
}
ready
Speed of pop
while (test = a.pop()) {
  result += test;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.