lazy vs eager es6

JavaScript performance comparison

Test case created by Carlos Vázquez

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function *iterMap(f, iter) {
    var e = iter.next();
    while (!e.done) {
      yield f(e.value);
      e = iter.next();
    }
  }
  
  function *arrayToIter(arr) {
    for (var i = 0, le = arr.length; i < le; i++) {
      yield arr[i];
    }
  }
  
  iterToArray = function(iter) {
    var arr = [], e = iter.next();
    while (!e.done) {
      arr.push(e.value);
      e = iter.next();
    }
    return arr;
  }
  
  map = function(f, arr) {
    for(var i = 0, le = arr.length, r = Array(le); i < le; i++) {
      r[i] = f(arr[i]);
    }
    return r;
  }
  
  lenght = 1000;
  array = Array(1000);
  for (var i = 0; i < length; i++) {
    array[i] = 1;
  }
  
  duplicate = function(d) {
    return d * 2;
  }

};
</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
Eager
map(duplicate, array)
pending…
Lazy
iterToArray(iterMap(duplicate, arrayToIter(array)))
pending…

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

0 Comments