As PHP is simpler for me I wished to benchmark algorithms in it for fun, and I chose to do factorials.
The recursive function completely flunked in speed when I got up to 80!
compared to the iterative method, and it gradually skyrocketed upwards while iterative had a steady line, actually it is something like this (x = factorial, y = seconds):
But in C/Java (which I just implemented the test in) show the same results to be only 1-5% off from eachother, almost the same speed.
Is it just useless to benchmark algorithms in this manner in scripting languages?
EDIT: For NullUserException:
function factrec($x) {
if($x <= 1) {
return $x;
} else {
return $x * factrec($x - 1);
}
}