▲ | fooker 2 days ago | ||||||||||||||||||||||||||||||||||
You’d be right if this was 1950. Since then literally all hardware, and compilers, have this specific use case so optimized that you’ll likely see the opposite if you benchmark it. | |||||||||||||||||||||||||||||||||||
▲ | CyberDildonics 2 days ago | parent [-] | ||||||||||||||||||||||||||||||||||
Prove it. You can put your stack data structure on the stack anyway. A balanced tree isn't going to have more depth than your memory address bit length. Why would copying a single value be slower than pushing an entire call frame to the stack? Locality is what matters and there is no truth to what you're saying. More important is the debugability. If you have a normal data structure you can see the full stack of values. If you use recursion you have to unwind through multiple call frames and look at each one individually. Recursion is for people who want to show a neat clever trick, it isn't the best way to program. | |||||||||||||||||||||||||||||||||||
|