recurse (v2)

Revision 2 of this benchmark created on


Setup

const n = 25

Test runner

Ready to run.

Testing in
TestOps/sec
recurse 1
const fact = (n) => {
    if (n === 0 || n === 1) return 1

    return n * fact(n-1)
}

fact(n)
ready
recurse 2
const fact2 = (n) => {
    const stack = [[n, 1]]

    while (stack.length > 0){
        const [curr, res] = stack.pop()

        if(curr === 0 || curr === 1) return res

        stack.push([curr - 1, res * curr])
    }
}

fact2(n)
ready
recurse 3
const fact3 = (n) =>{
    let res = 1
    for (let i = 1; i <= n; i++){
        res *= i
    }
    return res
}

fact3(n)
ready

Revisions

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