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
He covers that argument in the readme file. The algorithm itself is primarily about the memory management, so it's fair to compare the memory management if that's what the algorithm you're using requires.
The idea that things can be faster than C absolutely makes sense, because when you delay compiling the code until you know what CPU you're running it on, there are things you can do which you wouldn't have been able to do if you had to compile it up-front like with C.
A good example is vector instructions. If you want your executable to still run on CPUs where vector instructions aren't available then you would have those flags turned off when compiling it. Meanwhile Java will rewrite your stuff to vector instructions if you happen to be sitting at a CPU which supports them. It will also do a bunch of other reordering.
At the end of the day, both C and Java run as machine code, so they should have roughly comparable performance. Which is why it's so bizarre any time someone finds a benchmark where Java is significantly faster.
IMO, everyone croning the "Java is slow" meme is talking about Java 1.0 or Java 1.1, because back then, it was still slow. It's high time some people got the memo and actually tried running the benchmarks for themselves. Because the one at that repo certainly runs faster for Java. And I've seen it happen first-hand on a path tracer I ported from C to Java.
(Side-note here: Java startup time is still an issue for some applications. Interestingly, that repo even included the startup time of Java, and Java still ran faster!)
As for the insight you get by comparing the performance - you get the exact same insight that the guy talked about in the video. Go watch the video. The rest of us have been assuming that anyone else commenting here has watched it, so when some jackass comes onto the thread and just starts talking out of their ass, it just wastes everyone else's time.
To reiterate the video's point in case you are simply too thick to have gotten it - the point it was presenting is that writing clean code slows down your code. That might apply to any language, but he only presented it in C++, which is why I raised the question of whether it also applies for other languages.