Java is 1000 times faster than c++ on my computer???

This is a discussion on Java is 1000 times faster than c++ on my computer??? within the C++ Programming forums, part of the General Programming Boards category; Ok, this is driving me batty. I recently had an assignment to implement Floyds algorithm and Dijkstras on a graph ...

Java is 1000 times faster than c++ on my computer???

Ok, this is driving me batty. I recently had an assignment to implement Floyds algorithm and Dijkstras on a graph with 5403 vertices. (in java) my program was running impossibly slow so I started troubleshooting. As part of that troubleshooting I wrote a 3 level nested for loop in Java, and the same set of loops in C++. The Java version is running 1000 times faster than the C++ version. I just KNOW Java is not 1000 times faster than C++ Can anybody suggest what might be going on here? Here's the code

Add something to the innermost loop to prevent JIT from eliminating the inner loops or compile with the heaviest optimization your C++ compiler allows before trying to compile them. (That would be "-O3" for GCC.)

Languages are neither fast nor slow. Individual programs written with a particular implementation with particular data sets run with varying execution speeds. All we know from this test is that a particular Java program is 1000 times faster than a particular C++ program.

I wouldn't count on printing count at the end of program absolutely means that the loops actually get executed. I have seen compilers figure out that "the result of this is X" when it comes to simple loops that just adds 1 each time.

I'm very surprised that -O3 doesn't lead to good results, it normally does a good job on optimizing away loops.

The program that is slow is actually doing something (can't optimize inner loops away), as the unoptimized C++ program is doing something. It's not going to get faster than that.

Anon,
By impossibly slow I mean that the n^3 loop was going to take 4.5 hours to complete. That's what set me off on doing time tests. It appears that Eclipse was the problem. When running the java program from eclipse, each iteration of the outter for loop takes roughly 3 seconds. In the real program all it is doing is array[row][col] = math.min[array[row][col],array[otherRow][otherCol])
By running the program from a terminal window the time went from 4.5 hours to 4.5 minutes. Still, I would never have though that any java program would be faster, let alone so much faster, than compiled c++.

Cactus_Hugger. Now you've got me even more curious. It doesn't look like our computers are all that different in specs on the surface. Mine's an AMD 7750 with 512K cache and variable processor speed 1.3-2.7, 4G ram, and dual cores, but our times on the java program are so different. Are you executing it from the command line or from within an IDE?

And Matsp: Huh, thanks for the thought. I've never given any thought to what a compiler could or might do to optimize my code. It's interesting that that's never come up in my CS program so far.