|
|
|
|
|
by artsrc
4628 days ago
|
|
I agree that C code is currently faster than Java in most benchmarks: http://benchmarksgame.alioth.debian.org/u32q/benchmark.php?t... There is no contradiction that a compiler written in a language with expensive semantics (say python), could compile a program written in another language (say C) to produce highly efficient machine code. The JVM operations, such as JIT compilation and garbage collection, are bound by the performance of C code. The performance of the code you write depends significantly on the quality of the machine code produced by the JIT compiler. This quality of this code is not theoretically dependent on the implementation language of the JIT. |
|
Maybe not a contradiction in logic, no. But in practice the compiler has to solve a problem that is much harder than the problem the programmer would have to solve to write efficient C code for this one case. It's also one that has different complexity.
So you're in the situation now that a few compilers (VERY few, though this is very very hard to do) will actually beat stupid programmers in optimization, but there is nothing any compiler can do to beat the optimizations a good programmer will implement.
As for startup time, the sad part of that is that is one area where you could really improve C/C++ : startup time. Right now a C program has 4 distinct things that need to run before main() starts, and involve quite a bit of calculation, C++ has a lot more (the various kinds of initializers which can cause arbitrarily complex calculation).
A lot of these initializers result in constant (and small) memory layouts, and could in fact be run at compile time. What you generally do in initialization phase is to calculate registered classes (e.g. for serialization, or protocols) and make indexes of them. Maybe even compile regexes. All of that could be optimized to occur at compile time (as long as memory usage of the code is reasonable).