DEV Community

Discussion on: Recursion, Tail Call Optimization and Recursion.

Collapse
 
edisonywh profile image
Edison Yap • Edited

Interesting, can you elaborate on that?

P.S: And welcome to dev.to :D

Collapse
 
jccf091 profile image
JC

After Erlang/OTP R12B, a body-recursive function generally uses the same amount of memory as a tail-recursive function and generally hard to predict whether the tail-recursive or the body-recursive version will be faster.
With around 10, 000 elements, a body-reclusive function is about 10% faster. But with larger lists (like 10, 000, 000 elements), a body-reclusive function is about 97% lower and it is about as faster as the standard library map.

references:
Myth: Tail-Recursive Functions are Much Faster Than Recursive Functions
erlang.org/doc/efficiency_guide/my...
TAIL CALL OPTIMIZATION IN ELIXIR & ERLANG – NOT AS EFFICIENT AND IMPORTANT AS YOU PROBABLY THINK
pragtob.wordpress.com/2016/06/16/t...

Thread Thread
 
edisonywh profile image
Edison Yap

Wow that is interesting indeed, thanks for sharing!