v8 generators vs promises (v3)

Revision 3 of this benchmark created on


Description

Measuring native Chrome promises vs generators

Setup

var large = 100;
    
    // factorial using native promises
    
    function factorialPromises(n) {
      if (n <= 1) return Promise.resolve(1);
      return factorialPromises(n-1).then(function(res) { return n*res; })
    }
    
    
    // factorial using generators
    
    function * Factorial() {
      var n = 1,
        total = 1;
      while (true) {
        total = total * n++;
        yield total;
      };
    }
    
    function factorial(n) {
      var f = Factorial(),
        k, nf;
      for (k = 0; k < n; k += 1) {
        nf = f.next().value;
      }
      return nf;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
generators
factorial(large);
ready
native Promise
// async test

factorialPromises(large).then(function(e){ deferred.resolve(); });
ready

Revisions

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