FIFO unshift/pop vs push/shift

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var src = [];
    for (var i = 0; i < 2000; i++)
    src[i] = i;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
unshift/pop
src.unshift('b');
dest = src.pop();
src.unshift('c');
dest = src.pop();
src.unshift('d');
dest = src.pop();
pending…
push/shift
src.push('b');
dest = src.shift();
src.push('c');
dest = src.shift();
src.push('d');
dest = src.shift();
pending…
length/shift
src[src.length] = 'b';
dest = src.shift();
src[src.length] = 'c';
dest = src.shift();
src[src.length] = 'd';
dest = src.shift();
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:

0 comments

Add a comment