O
Oliver Wong
tom fredriksen said:Thats where you are wrong, they are then not equally efficient at a
machine code level or cpu level or whatever you want to call it.
When you start talking about machine code, you're no longer talking
about just the programming language, but also the compiler and Virtual
Machines (if applicable) as well. That was my main point.
All of the three above statements are valid to a certain extent, but it
still does not disprove my statement.
Argh.. It annoys me that a lot of people programming higher level
abstraction languages, compared to C, don't realise that the language is
less runtime efficient because of all the implications of higher level
abstractions in the language, which are inherent. Java and other
interpreted languages are good languages, and I love them as well, but
that does not mean they do not have there problems and that they have
their areas of use and disuse.
This is not nescessarily so. A program written in Java, when compared to
a similar program written in C, may perform slower with one particular
Compiler/JVM/OS/Architecture/Machine configuration, but may before better in
a different one.
Consider, for example, the MMX, SSE and other "specialized" instruction
sets. If you were to code in a low level language, you might write code that
says "Okay, multiply the value in this register by the cosine of the value
in that register; next take the sine of this value, add it to that value in
that register;" and so on, and have 20 operations.
In a high level language, you might have something like
"polygon.rotate(27)".
When the compiler sees the lower level instructions, it can try to do
some sort of peephole optimization, but the compiler doesn't have a "big
picture" idea of what you're trying to accomplish.
With the high level code, the compiler could say "Oh, I see what he's
trying to do. He's trying to rotate a polygon about the origin. Well, using
SSE, I can do that in a single clock cycle." and so the compiler puts in the
appropriate instruction.
In other words, your general perception that Java is "slower" than C,
probably has very little to do with the fact that Java is a higher level
language than C. I claim that higher level languages are easier to optimize,
because they provide the optimizer with more metadata. Of course, in an
ideal world, our optimizers would produce the best possible code, regardless
of whether extra "hints" were provided or not.
The reason you might have this perception is that you're probably
measuring a program being compiled to bytecode and run on a virtual machine
on top of a Win32 platform (for example) against a program compiled to
native Win32. So you're adding an extra layer of interpretation.
Again, I stress that this is not simply an issue of programming
language, but the entire stack of language, compiler, virtual machine, OS,
architecture, machine configuration.
Of course if there was another language which could consistently show
better performance than C with higher abstraction levels so that the OS
could have more advanced features or less errors and security problems,
then that would be the reason. Unfortunately it is not so.
I'm not sure I understand what you're saying here. Are you disputing my
above claim, or just making an unrelated side remark, or what?
Generally I agree as well. But 30-40 years more with expertise of how to
create compilers and processors have made an impact on what makes an
efficient program. Thats mostly the area where the modifications would be.
Yes, compilers have improved over time. But that doesn't mean that
programmers are now better at guessing where the bottleneck in their program
lies. I think Knuth is still correct, even today, when he asserted "It is
often a mistake to make a priori judgments about what parts of a program are
really critical, since the universal experience of programmers who have been
using measurement tools has been that their intuitive guesses fail."
- Oliver