Generator vs Array

JavaScript performance comparison

Test case created by nzakas

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function *generate() {
      yield 1;
      yield 2;
      yield 3;
      yield 4;
      yield 5;
      yield 6;
      yield 7;
      yield 8;
      yield 9;
      yield 10;
  }
  
  function pushAll() {
      let result = [];
      result.push(1);
      result.push(2);
      result.push(3);
      result.push(4);
      result.push(5);
      result.push(6);
      result.push(7);
      result.push(8);
      result.push(9);
      result.push(10);
      return result;
  }

};
</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
Generator
const result = [...generate()];
pending…
Array
const result = pushAll();
pending…
Array + Iterator
const result = [...pushAll()];
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