I am looking for an algorithm (or an argument of such an algorithm) in a functional style that is faster than imperative.
I like the functional code because it is expressive and basically easier to read than real pendants. But I also know that this expressiveness can be worth the overhead. Not always due to methods like tail recursion, but often they are slower.
During programming, I don’t think about the time it takes to execute functional code, because these days PCs are very fast and development time is more expensive than runtime. In addition, for me, readability is more important than performance. However, my programs are fast enough, so I rarely have to solve the problem for real.
There are some algorithms that in practice should be implemented in an imperative style (for example, sorting algorithms), otherwise in most cases they are too slow or require a lot of memory. Unlike methods such as pattern matching, an entire program, such as a parser written in a functional language, can be much faster than written in an imperative language because of the ability of compilers to optimize code.
But are there any algorithms that are faster in a functional style or are there options for customizing the arguments of such an algorithm?
source share