Array shift vs pop

Benchmark created by cGuille on


Setup

var arr1 = [],
        arr2 = [],
        arr3 = [],
        arr4 = [],
        i;
    
    for (i = 0; i < 10; ++i) {
        arr1.push(i);
    }
    for (i = 0; i < 100; ++i) {
        arr2.push(i);
    }
    for (i = 0; i < 1000; ++i) {
        arr3.push(i);
    }
    for (i = 0; i < 10000; ++i) {
        arr4.push(i);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
shift
arr1.shift();
arr2.shift();
arr3.shift();
arr4.shift();
ready
pop
arr1.pop();
arr2.pop();
arr3.pop();
arr4.pop();
ready

Revisions

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

  • Revision 1: published by cGuille on