Foreach vs. loop (counting)

Benchmark created on


Setup

var items = [],
        i, len;
    len = 100000;
    for(i = 0;  i < len;  ++i) {
        items.push(i);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
ForEach
var total = 0;
items.forEach(function(value) {
    total += value;
});
ready
Loop
var total = 0;
for (i = 0, len = items.length;  i < len;  ++i) {
    total += items[i];
}
ready

Revisions

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