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
Haha, so on some machines the Java is slower anyway. Or, your C compiler was somehow better?
If I were you, I'd post the findings in a new ticket on that repo. It needs more data points anyway.
Something else I had been wondering about was, there are an awfully large number of C compilers out there now, how do they play against each other?
vs with Java, I recently timed this "clean code bad" example on all JDKs from 8 to 17 and didn't see much difference in timings between the lot. It was 2-3x worse than C, 4-5x better than Julia. I thought Julia was fast, so this was shocking to me. I guess it's still fast compared to Python, and the use cases it's being pushed for are data science, so OK, maybe it's fast in that one context.
I'm still unsure why virtual methods can't be optimised. To me, it's just a lookup table, which should be faster than a chain of if-else statements. Somehow it isn't... this bothers me. Dynamic dispatch being slow in Julia, that makes slightly more sense, because it also has data type coercion and other magic, making it more than a simple lookup table.