Performance comparison of a custom gcd() function in Julia, C, and Rust

A cursory look at the assembly created reveals that gcc rewrites the recursion to a loop. Julia does not. I haven’t checked, but I guess that rust also does this kind of tail recursion optimization.

So, this huge difference is typical for tail-recursive functions doing very little at each stage.

9 Likes