for vs forEach vs while vs Underscore.js

JavaScript performance comparison

Revision 391 of this test case created by

Preparation code

<script src="https://raw.githubusercontent.com/lodash/lodash/3.10.1/lodash.min.js"></script>
<script>
  const values = new Set()
  for (var i = 0; i < 10000; i++) {
    values.add(i)
  }
</script>
    

Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
forEach
var a = 0
values.forEach(function(i){
  a += i
})
pending…
for...of
var a = 0
for (var i of values) {
 a += i
}
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.

0 Comments