 So while I think functional programming offers tons of great things and that's why you'll see a lot of like function purity and other other aspects of functional programming within my code Like pretty much everything else. I don't view any single paradigm as a singer as a silver bullet We really got to talk about recursion versus iteration and Why I think one is superior to another Well, I have some boilerplate here just so that I'm not writing the timer stuff But we're going to define a function that does a countdown using recursion and another function that does a countdown using iteration and Apparently completely forget how to type typical me. So what this will need to do is of course take a value We'll just use an integer Sorry, I said functions just because it's a functional programming thing Adam makes an important distinction and these Should actually be procedures because there's nothing we need to return. It's just going to call itself continuously so then with any Recursive function we need an exit condition and to check for that now. We're just going to count down to zero so a value equals zero Then return I Need a semicolon and then quite literally just call a countdown again with The value minus one and that is for iteration. We can define the function again our procedure again So we need to do one thing slightly different here, or we're just gonna Assign this to a variable Let's do a These greater than zero Loop Okay, now these should do the same thing and they're being called the same way and we're going to pass We're passing the same exact value to each of these to make this longer especially since integer operations are very fast. We're going with the the total range of Natural and natural numbers So this is going to be counting down quite a bit Make sure this builds and that I didn't make any typos Actually, I'm going to optimize this So a few runs of this you can tell that recursion takes quite a bit longer than iteration We'll optimize this slightly further just to see if this makes any difference. I really don't recommend building at optimization level three for anything GCC After just years of doing it it can change code a little too drastically But you can see recursion still takes quite a bit longer there are some times where it comes pretty close I Not entirely sure why this deviation would be occurring at all Maybe somebody intimately familiar with the runtime can explain that to me But I regularly see cases of this I've done similar stuff in functional programming languages and even Well, I've done stuff with JavaScript recently and It was ECMAScript 6 so it did have the The recursion limit eliminated and the One of what did they call it tail end recursion optimization in place and Yet still I was seeing iteration outperform recursion Now that's not to say that recursion is useless. There are instances in which recursion is capable of Accomplishing things iteration isn't such as converting a Say a dictionary into a tree One possible way to do that is through recursion and it is remarkably difficult Depending on the language may be even impossible to implement that through iteration But if you're just going through something like we did countdown or going through a list or similar things iteration is Overwhelmingly the better option So I should explain the performance reasons why why there is a discrepancy between these two without getting into the assembly and You can easily write this for yourself and look at the assembly if you through whatever Disassembler you you like if you want to go that route It has to do with What's going on internally to accomplish this in the case of iteration? It's very simple. We can actually replace this whole thing with We do a label We'll just call it start and then go to start and then if What was the condition if v? Equal or yeah v equals zero Then return this is internally or this is this is Functionally identical this will accomplish the exact same thing and well Almost compile down to the exact same thing the The exact logic comparison is slightly different. I had a greater than before but it's just an equal now Actually, no, it's just why How does that work exactly at that? Doesn't matter doesn't matter Otherwise these are doing the same thing every time after we do the assigning v equal to V minus one. They're just decrementing it There's a jump back to this label This is all the loop does is it's just a continuous jump up to here until This statement is true So that's all that's happening is a jump operation in code With the recursion because there's a function call. It's jumping all Function calls involve a jump, but there's also some setup for the function if the function it I'm using function as a synonym for procedure here, uh any subroutine if the function Has a small enough amount of parameters and those parameters are capable of fitting in registers then what will happen is instead of a call stack the The parameters are put into certain registers if it's complicated enough Well, you have to build up a whole call stack of all the different Of all the different parameters, but in this case, it's just also puts the value into a register and then Decrements it puts it into the register decrements it puts it into the register and so on essentially, it's the additional setting up of the Function environment that causes recursion to be slightly slower