Programming languages

J Langley
J Langley
Joined: 30 Dec 05
Posts: 50
Credit: 58338
RAC: 0

RE: Java's not a bad

Message 60311 in response to message 60296

Quote:
Java's not a bad langauge, but not a good choice for highend scientific computing.


Agreed.

Quote:
The costs of compiling into intermediate code during development and only being converted into machine code at runtime (you can do much more agressive compiler optimizing if you do it all at once since you're not limited timewise) ... mean that niether Java, .Net, or any of thier successors are ever likely to be able to get faster raw performance than C++.


Not true. Runtime compilation does give you a runtime overhead when the compilation is done, but there are certain optimizations that Runtime compilers can do that static compilers can't (because Runtime compilers have more information available to them), so in some cases a Runtime compiled program can outperform a statically compiled program.

Since Java is an "early escape" language (i.e. one where not all conditions of an IF statement have to be evaluated before the subsequent action is started), Java Runtime compilers can reorganize code to improve performance. Consider the following example:

IF (conditionA) OR (conditionB)
DO something

in a statically compiled language the order of evaluation will be preserved (a *very* smart compiler *might* reorder if it can determine that calculating conditionB is cheaper in terms of CPU cycles than calculating condtionA, but I'm not aware of any compiler that does this); in a Runtime compiler, the compiler can spot that conditionA is rare whereas conditionB is common, and can thus reorder the assembler equivalent to

IF (conditionB) OR (conditionA)
DO something

which will save the CPU cycles needed to evaluate conditionA.

Java is just as fast as C++ in most cases, faster in some, and slower in others. The idea "C++ is always faster than Java" was justified in the early days of Java, but is no longer valid.

Mike Hewson
Mike Hewson
Moderator
Joined: 1 Dec 05
Posts: 6534
Credit: 284710168
RAC: 110462

RE: The costs of compiling

Message 60312 in response to message 60311

Quote:
The costs of compiling into intermediate code ..... but is no longer valid.


Is it true that one can compile right through to ( now platform dependent ) machine code prior to execution with Java?

It would still conform to operational behaviour as per the JVM specs but be quite precisely actualised.

Cheers, Mike.

I have made this letter longer than usual because I lack the time to make it shorter ...

... and my other CPU is a Ryzen 5950X :-) Blaise Pascal

J Langley
J Langley
Joined: 30 Dec 05
Posts: 50
Credit: 58338
RAC: 0

RE: Is it true that one can

Message 60313 in response to message 60312

Quote:
Is it true that one can compile right through to ( now platform dependent ) machine code prior to execution with Java?

Certainly for Windows there are tools to convert Java code into a native .exe (not sure about otehr platforms); but it has been a while since I looked at these, so I don't know whether they currently produce faster code than the modern Java runtime compilers do.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.