Why is this js code so slow?
Posted
by
SpiderPig
on Stack Overflow
See other posts from Stack Overflow
or by SpiderPig
Published on 2012-07-02T03:12:14Z
Indexed on
2012/07/02
3:15 UTC
Read the original article
Hit count: 111
JavaScript
This code takes 3 seconds on Chrome and 6s on Firefox. If I write the code in Java and run it under Java 7.0 it takes only 10ms. Chrome's JS engine is usually very fast. Why is it so slow here? btw. this code is just for testing. I know it's not very practical way to write a fibonacci function
fib = function(n) {
if (n < 2) {
return n;
} else {
return fib(n - 1) + fib(n - 2);
}
};
console.log(fib(32));
© Stack Overflow or respective owner