recursion

Benchmark created by Truong Nguyen on


Test runner

Ready to run.

Testing in
TestOps/sec
recursive funcntion
function factorial(n) {
  if (n == 0)
    return 1
  else {
    return n * factorial(n - 1);
  }
}
console.log(factorial(10));
ready
using loop
function ifN(n) {
  var s = 1;
  if (n === 0)
    return s;
  else {
    for (var i = 1; i <= n; i++) {
      s *= i;
    }
    return s;
  }
}
console.log(ifN(10));
ready

Revisions

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

  • Revision 1: published by Truong Nguyen on