There is this book that I’ve been reading for a bit of fun.
Computational Fairy Tales by Jeremy Kubica.
Within this book there is a section called computational Graffiti.
The following snippet
Code C - [expand] |
1
2
3
4
| Int RecursiveAdd (int n, int m) {
If (m == 0) return n;
Return RecursiveAdd(n, m-1) +1;
} |
The book makes jest at the inefficiencies of it all.
I haven’t got the means to compute this atm, I want to know why this is BAD.
I can see the function gets called m+1 times.
Doesn’t the recursive add work exactly the same way as for (i==1; i<m; i++) ?
Is it inefficient because i cpu could just use sum and carry register on a multi bit word and therefore do this all in one clock cycle? with opcode +
Regards,
Wes