factorial_cached (v2)

Revision 2 of this benchmark created on


Setup

function factorial_cached(n) {
	console.log(n);
    factorial_cached.cache ||= [1];
    if(!factorial_cached.cache[n]) {
        factorial_cached.cache[n] = n * factorial_cached(n - 1);
    }
    return factorial_cached.cache[n];
    
}

function factorial(n) {   
	console.log(n)
	if(n>2) return 1;
    return n*factorial(n-1);
}

Test runner

Ready to run.

Testing in
TestOps/sec
factorial_cached
factorial_cached(2100)
ready
factorial
factorial(2100)
ready

Revisions

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