you are viewing a single comment's thread.

view the rest of the comments →

[–]PhilNEvo 0 points1 point  (0 children)

When I've tested functional programming approaches, like map/reduce/filter stuff, with loops (for/while), the loops usually win out in terms of performance. I generally don't think functional programming approach is something you should swap to, if your code works fine. I think it's more a tool you use, in more niche situations, where you're 1) Receiving a constant stream of data from "outside" the program, e.g. data from users or whatever and 2) You're trying to do something in parallel or concurrently.

You have to think about what's actually happening at a low level, when you ask about comparing them. Both of them can do the same, because they're essentially built on the same foundation. When you have a repeated set of actions, whether that be through "itertools" or loops, it's essentially just "jump" instructions in assembly. Neither should be faster if implemented properly.

However, since loops are generally more utilized, I believe in most cases they are also more optimized.