[Shootout-list] ackermann, fibonacci and takfp benchmarks
Daniel South
WildCard_25@HotMail.Com
Sat, 19 Mar 2005 21:13:59 +1000
Einar Karttunen wrote:
| "¤WildCard¤" <WildCard_25@HotMail.Com> writes:
||
|| Easy to add to existing programs. At the start of each function.
|| recursion += 1;
|| depth +=1;
|| if (depth > maxdepth) {maxdepth = depth;}
|
| This is actually more expensive than recursion in many languages.
Not really, generally, allocating a new stack frame is more expensive
than a comparison. The difference will be that global scope variables
will be changed on every call and *then* compared to, making it harder
to for the compiler to optimise out the recursion ie. it rely has to
recurse and not just use a cached value. This will of course impact the
languages that had been optimising out the recursions, but the whole
point is to test the cost of calling the function, not to test how well
the compiler optimises. Tail recursion optimisation should not be
affected, just the caching.
As a side note: in what languages would a register comparison be more
expensive than stack frame allocation?
Daniel South