LiveScript Factorial

Benchmark created on


Setup

fac1 = function(n) {
      var r = 1;
      for (var i = 2; i <= n; i++) {
        r *= i;
      }
      return r;
    }
    
    fac2 = function(n) {
      var r = 1;
      while (n > 1) {
        r = r * n--;
      }
      return r;
    }
    
    // This function was compiled from:
    // fac3 = (n) -> product [1 to n]
    var fac3;
    fac3 = function(n) {
      return product((function() {
        var i$, to$, results$ = [];
        for (i$ = 1, to$ = n; i$ <= to$; ++i$) {
          results$.push(i$);
        }
        return results$;
      }()));
    };
    product = function(xs) {
      var result, i$, len$, x;
      result = 1;
      for (i$ = 0, len$ = xs.length; i$ < len$; ++i$) {
        x = xs[i$];
        result *= x;
      }
      return result;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
For-Factorial
fac1(42);
ready
While-Factorial
fac2(42);
ready
LiveScript-Factorial
fac3(42);
ready

Revisions

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