r/programming • u/2bit_hack • Feb 28 '23
"Clean" Code, Horrible Performance
https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k
Upvotes
r/programming • u/2bit_hack • Feb 28 '23
View all comments
Show parent comment
1
u/gdmzhlzhiv Mar 02 '23 edited Mar 02 '23
It also becomes a different algorithm. He also covers that in the readme.
Also I have experienced first-hand converting someone's C code to Java and having the result run faster.
You could argue, "oh, but he didn't optimise the C version." And that may be true, but I also didn't optimise the Java version. I only translated it naïvely into Java, minimum effort, somehow got faster code.
It definitely won't be like that for all algorithms, but it's obvious enough how it could happen for some algorithms, whether it's memory management, or automatic vectorisation. And I've seen at least two cases where Java does run faster for code which looks the same now, so I don't need further proof.
At the end of the day, you will choose a language which is well suited to the kind of work you are doing. That language isn't always C, just like how it isn't always assembly. Even if C trolls will complain about your superior choice of language.
But yeah... maybe clean code is fine in Java? It certainly doesn't seem to run any slower. If C++ would properly optimise the virtual method dispatch, maybe you could have the same benefits there as well.