forEach vs for..of

JavaScript performance comparison

Revision 4 of this test case created by Mahdi Yari

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const randomStrings = [];
  for (let i = 0; i < 10000; i++) 
  {
      randomStrings.push(Math.random().toString(36).substring(10));
  }
  const randomStringsCopy = [];

};
</script>

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
randomStrings.forEach((val) => 
{
    randomStringsCopy.push(val);
});
pending…
for..of
for (let randomString of randomStrings)
{
    randomStringsCopy.push(randomString);
}
pending…

Revisions

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

0 Comments