Pop vs for loop and new

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function someOp(a) {
      return a + 1
    }
};
</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
Pop : 10-length array
var a = []
for (var i = 0; i < 10; i++)
a.push(i)

while (a.length != 0)
someOp(a.pop())
pending…
For-and-new : 10-length array
var a = []
for (var i = 0; i < 10; i++)
a.push(i)

for (var i = 0; i < a.length; i++)
someOp(a[i])

a = []
pending…
Pop : 5-length array
var a = []
for (var i = 0; i < 5; i++)
a.push(i)

while (a.length != 0)
someOp(a.pop())
pending…
For-and-new : 5-length array
var a = []
for (var i = 0; i < 5; i++)
a.push(i)

for (var i = 0; i < a.length; i++)
someOp(a[i])

a = []
pending…
Pop : 3-length array
var a = []
for (var i = 0; i < 3; i++)
a.push(i)

while (a.length != 0)
someOp(a.pop())
pending…
For-and-new : 3-length array
var a = []
for (var i = 0; i < 3; i++)
a.push(i)

for (var i = 0; i < a.length; i++)
someOp(a[i])

a = []
pending…

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

Compare results of other browsers

0 comments

Add a comment