proc rec fact

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
proc
function factorial(n) {
    let result = 1;
    for (let i = 1; i <= n; i++) {
        result *= i;
    }
    return result;
}

factorial(5);
ready
rec
function factorial(n) {
    return fact_iter(1, 1, n);
}
function fact_iter(product, counter, max_count) {
    return counter > max_count
           ? product
           : fact_iter(counter * product,
                       counter + 1,
                       max_count);
}

factorial(5);
ready

Revisions

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