r/learnjava • u/IIwarrierII • Nov 03 '20
Why is c faster than java?
If I were to make the same thing in java would it now be as fast ?
58
Upvotes
r/learnjava • u/IIwarrierII • Nov 03 '20
If I were to make the same thing in java would it now be as fast ?
2
u/J_Peanut Nov 04 '20
There are a lot of comments here explaining the differences between the compilation of Java and C - but I have found there are two aspects missing:
C is a language intended to be compiled directly to assembly. If you write code in C, you can predict how the generated assembly code will look. This allows programmers to optimise their code to a very high degree.
Benchmark programs are generally using C to measure the performance. They do this because C allows very specific interactions with the system and also because it has been established for that. Taking point 1. into account, it is possible to optimize systems to execute assembly generated by C. This is not the reason why C is fast, but one of the reasons why C runs just so good.