Pratap koritala wrote:Will OpenJDK license allow me for this customization...?
Is it?Pratap koritala wrote:As you know JAVA Array access is 2X-3X slower than C or Equivalent Language without bound checks...
Campbell Ritchie : Is it?
To the example with the try-catch: This is simply bullshit! To catch and ignore an exception which would tell you that your application has tried to use a wrong array index (and of course other exceptions, too) is plain stupid. In almost all cases this exception could give you valuable hints to a bug in your application logic.
I don't think it is a bull shit, you are potentially eliminating one condition.. (i<n)
As you know JAVA Array access is 2X-3X slower than C or Equivalent Language without bound checks...
Where are these online judges? Please quote a link.Pratap koritala wrote:
Campbell Ritchie : Is it?
I strongly recommend to visit Online judges for Proof...
ArrayIndexOutofBounds surely helps but not when I know what I am doing(Certainly)..
Henry Wong wrote:
Where did you get your 2X-3X slower than C numbers from?
Isn't your instruction pipeline will fail because of if condition...
Isn't that overhead to check for bounds by if loop...
Isn't that overhead analyzing the code for possible optimization, which will never happen because of complex code...(Excluding compile time)
Hang on, I'll give the proof in figures... (Please remember this is not java VS SOMETHING DEBATE...)
2X-3X is about only the code related to Accessing the array...( Marco Ehrentreich posts has been helpful)
I merely asked for backup for the number that you threw out as an "as you know" fact
Man! I bet every Microsoft programmer who wrote a C++ buffer overflow security risk said exacty the same thing.
Pratap koritala wrote:I'm merely pointing to a feature rather than weakness...
To say concretely ,
In the above code, Do I really need one more boundary check...
I merely asked for backup for the number that you threw out as an "as you know" fact
After that, I changed it to C++ and it ran within the time limit. Difference is around 1.5-1.7 times ( The Claim I made 2x-3x is array access time that I derived from the differences).
Steve
So, your question shouldn't be: Java is slower than C++ because of boundary checks, how can I get rid of the boundary checks? It should be: This code sample runs slower in Java than I need it to. How can I make it faster? Or: This code runs too slow in Java, but not too slow in C. Should I run this code in Java or not?
A language Extension(Apart from regular arrays) for targeted programmers (who participate in Programming Competition) to use this kind of feature..
Perhaps it suggests a need to optimize your code rather than inherent speed differences in languages.
What kind of optimization needed, if the same code is performed good on the other one
Marco Ehrentreich wrote:2) In case the application doesn't run long enough for the JIT compiler to optimize anything, as far as I know it could help to use a server JVM which usually has a higher startup time but does more optimizations before the application starts.
Marco Ehrentreich wrote:Just out of curiosity, does anyone know some tutorials or articles with a comprehensive list of common optimizations a typical JIT compiler in Java will make?
So it seems that the server VM may make this optimization but not the client VM.Range check elimination -- The Java programming language specification requires array bounds checking to be performed with each array access. An index bounds check can be eliminated when the compiler can prove that an index used for an array access is within bounds.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
So it seems that the server VM may make this optimization but not the client VM.
The client VM compiler doesn't try to execute many of the more complex optimizations performed by the compiler in the server VM, but in exchange requires less time to analyze and compile a piece of code. This means the client VM starts up faster and requires a smaller memory footprint.
@Henry: According to the Sun docs it's really the client VM which has faster startup time. But because server and client VM/compiler support different levels of optimization techniques the situation has changed anyway.
henry wong wrote:I merely asked for backup for the number that you threw out as an "as you know" fact
Pratap koritala wrote:Just wanted to give you actual figures on much simpler code...
Is this "AS YOU KNOW FACT"? ( Now,difference is clearly visible)
Don't get me started about those stupid light bulbs. |