C/C++ vs. Java - a simple speed test.
I have read your prior discussions about Java. Since most comments seams to be non-true (ie. lame comments about java is slower than C because....).
I think most of you don''t have a clue and just thinks that C is much more faster than java because java is only byte-compled etc.
However to prove that java was compatible to C/C++ I did a small test with my teacher (who was just as incompetent as you and promoting that C would kick Javas azz), he suggested an equal bubblesort test...
NOTE. My goal is/was only to show that slow enougth for makeing speed-critical applications. Not to show that java is faster or slower than C in some specific test. Only to show they don''t always differ.
I wen''t home- wrote a java-version and asked a friend to make an boublesort in C or C++ with the same agreed competition-rules.
He made one in C, and we began our benchmark.
http://burk.hax.se/~nils/javavsc_eng.html
Well... as you can see java won over C in speed in this test.
However I am now searching for prime-numbers with my selfmade Java-program - since C is too slow. :-)
Nils Höglund (prothall@burk.hax.se)
hehe, replace
int sortTemp;
with
register int sortTemp;
And ye shall se da power of c...
And for good sake, turn on the optimizer.
Using pointer instead of indexing should further speed up the code.
int sortTemp;
with
register int sortTemp;
And ye shall se da power of c...
And for good sake, turn on the optimizer.
Using pointer instead of indexing should further speed up the code.
Don''t be silly. Java is faster or as fast as c in native code.
It''s just that java has two main (IMHO) things about it:
1) Graphics things are slow and use too much memory in java.
2) Complining a java takes 5-10x longer than c/c++.
But the latter is just my oppinion; the former is the real reason java is considered slower.
It''s just that java has two main (IMHO) things about it:
1) Graphics things are slow and use too much memory in java.
2) Complining a java takes 5-10x longer than c/c++.
But the latter is just my oppinion; the former is the real reason java is considered slower.
Hmm, I tried the C program on a machine that is 15 percent faster using MSVC and got 33 percent reduction in the C execution time.
Simple tests like these are pointless and don't prove anything.
Edited by - TimSmith on March 31, 2001 10:22:58 AM
Simple tests like these are pointless and don't prove anything.
Edited by - TimSmith on March 31, 2001 10:22:58 AM
March 31, 2001 09:42 AM
Java and C/C++ are simply languages... please remember that it''s not necessarily the *language* that is slow, rather it is the implementation of that language on a given platform.
For instance, JVMs have a bad reputation as being quite slow - and to some extent, that is a valid concern. However, there are ways around that. JIT compilers help... and nothing beats compiling your Java code to native (ie: using GCJ for instance)... but again, each Java->native compiler has it''s own quirks. Since garbage collection in Java is semi-automatic, a native compiler has to build that GC into whatever it spits out... depending on the algorithms it uses, your final product might be very, very, very fast, or downright ugly.
Finally, not all JVMs are equal. On the Linux platform for instance, the Sun/Blackdown JVM is *slow*. IBM''s JVM (freely available) is much faster, although still pokier than the Sun JVM for Windows. I''m playing with the Tao Group''s "Intent" environment at work (not quite a JVM exactly, but it does execute Java code), and it seems reasonably fast - that is, if you can stand the build process.
At any rate, it isn''t a fair comparison to generalize and say "Java is slower than C++"... you need to look at the various implementations of each language, and make your decisions from there.
For instance, JVMs have a bad reputation as being quite slow - and to some extent, that is a valid concern. However, there are ways around that. JIT compilers help... and nothing beats compiling your Java code to native (ie: using GCJ for instance)... but again, each Java->native compiler has it''s own quirks. Since garbage collection in Java is semi-automatic, a native compiler has to build that GC into whatever it spits out... depending on the algorithms it uses, your final product might be very, very, very fast, or downright ugly.
Finally, not all JVMs are equal. On the Linux platform for instance, the Sun/Blackdown JVM is *slow*. IBM''s JVM (freely available) is much faster, although still pokier than the Sun JVM for Windows. I''m playing with the Tao Group''s "Intent" environment at work (not quite a JVM exactly, but it does execute Java code), and it seems reasonably fast - that is, if you can stand the build process.
At any rate, it isn''t a fair comparison to generalize and say "Java is slower than C++"... you need to look at the various implementations of each language, and make your decisions from there.
changing
int sortTemp;
to
register int sortTemp;
and compile it with lcc_win32 with optimazation on.
made it run in 770 ms.
and lcc_win32 is not a fast compiler so I don''t know what the heck you did to make it run so slow.
I have a athlon 700, the same as you did so that''s not the problem.
It shouldn''t be that hard to make it a lot faster. In c that is.
int sortTemp;
to
register int sortTemp;
and compile it with lcc_win32 with optimazation on.
made it run in 770 ms.
and lcc_win32 is not a fast compiler so I don''t know what the heck you did to make it run so slow.
I have a athlon 700, the same as you did so that''s not the problem.
It shouldn''t be that hard to make it a lot faster. In c that is.
March 31, 2001 10:07 AM
>At any rate, it isn''t a fair comparison to generalize and >say "Java is slower than C++"... you need to look at the >various implementations of each language, and make your >decisions from there.
Exactly my point!
My (stupid) test was not to prove that Java is faster than C. But to get people to realize how stupid the argumentation "java is slower than C" is, I had to partly do that.
I know you can "cheat" with the C-version of my example ie. changing the array''s to global variables (avoiding it to be copied to the stack) etc etc.
Java is competative with C/C++ in speed. Not necessary faster or slower.
GUI implementations in Java (ie. AWT or Swing) has slow implementations in some JVM. However implmentations of Java3D and java2D is supposed to be quite fast.
And GC is not necessary slow. The JVM''s is getting better and better, faster and faster.
I hope more people will realize that java is not a bad choice for programming and development. But a secure chioce with alot of featurs like RMI, threading.. But it completly depends what your goals are and what you are doing. Ie. Orion (completly written in java) is significant faster than Apache (written in C) serving even static webpages.
I beleve that Java has the right potentials to become far more used than it is today. With featers like a great API, GC, threading etc. it''s very easy to use and implement.
But again - it depends what you''re trying to do.
Please comment futher!
Nils Höglund (prothall@burk.hax.se)
Exactly my point!
My (stupid) test was not to prove that Java is faster than C. But to get people to realize how stupid the argumentation "java is slower than C" is, I had to partly do that.
I know you can "cheat" with the C-version of my example ie. changing the array''s to global variables (avoiding it to be copied to the stack) etc etc.
Java is competative with C/C++ in speed. Not necessary faster or slower.
GUI implementations in Java (ie. AWT or Swing) has slow implementations in some JVM. However implmentations of Java3D and java2D is supposed to be quite fast.
And GC is not necessary slow. The JVM''s is getting better and better, faster and faster.
I hope more people will realize that java is not a bad choice for programming and development. But a secure chioce with alot of featurs like RMI, threading.. But it completly depends what your goals are and what you are doing. Ie. Orion (completly written in java) is significant faster than Apache (written in C) serving even static webpages.
I beleve that Java has the right potentials to become far more used than it is today. With featers like a great API, GC, threading etc. it''s very easy to use and implement.
But again - it depends what you''re trying to do.
Please comment futher!
Nils Höglund (prothall@burk.hax.se)
>At any rate, it isn''t a fair comparison to generalize and >say "Java is slower than C++"... you need to look at the >various implementations of each language, and make your >decisions from there.
Exactly my point!
My (stupid) test was not to prove that Java is faster than C. But to get people to realize how stupid the argumentation "java is slower than C" is, I had to partly do that.
I know you can "cheat" with the C-version of my example ie. changing the array''s to global variables (avoiding it to be copied to the stack) etc etc.
Java is competative with C/C++ in speed. Not necessary faster or slower.
GUI implementations in Java (ie. AWT or Swing) has slow implementations in some JVM. However implmentations of Java3D and java2D is supposed to be quite fast.
And GC is not necessary slow. The JVM''s is getting better and better, faster and faster.
I hope more people will realize that java is not a bad choice for programming and development. But a secure chioce with alot of featurs like RMI, threading.. But it completly depends what your goals are and what you are doing. Ie. Orion (completly written in java) is significant faster than Apache (written in C) serving even static webpages.
I beleve that Java has the right potentials to become far more used than it is today. With featers like a great API, GC, threading etc. it''s very easy to use and implement.
But again - it depends what you''re trying to do.
Please comment futher!
Nils Höglund (prothall@burk.hax.se)
Exactly my point!
My (stupid) test was not to prove that Java is faster than C. But to get people to realize how stupid the argumentation "java is slower than C" is, I had to partly do that.
I know you can "cheat" with the C-version of my example ie. changing the array''s to global variables (avoiding it to be copied to the stack) etc etc.
Java is competative with C/C++ in speed. Not necessary faster or slower.
GUI implementations in Java (ie. AWT or Swing) has slow implementations in some JVM. However implmentations of Java3D and java2D is supposed to be quite fast.
And GC is not necessary slow. The JVM''s is getting better and better, faster and faster.
I hope more people will realize that java is not a bad choice for programming and development. But a secure chioce with alot of featurs like RMI, threading.. But it completly depends what your goals are and what you are doing. Ie. Orion (completly written in java) is significant faster than Apache (written in C) serving even static webpages.
I beleve that Java has the right potentials to become far more used than it is today. With featers like a great API, GC, threading etc. it''s very easy to use and implement.
But again - it depends what you''re trying to do.
Please comment futher!
Nils Höglund (prothall@burk.hax.se)
March 31, 2001 10:37 AM
quote:
Original post by zel
hehe, replace
int sortTemp;
with
register int sortTemp;
And ye shall se da power of c...
And for good sake, turn on the optimizer.
Using pointer instead of indexing should further speed up the code.
For the umpteens time: Compiler optimization *was* turned on.
And if you start using pointer arithmetic, you are changing the problem alltogether, which defeats the purpose of the original test.
March 31, 2001 10:39 AM
quote:
Original post by Shadow Mint
1) Graphics things are slow and use too much memory in java.
Depends on the API. If you are referring to Swing, complain about Swing, not Java.
The only real problem with graphics in Java without special JVM support is that you cannot directly access the video memory (-> more copying). This will be partly solved in JDK 1.4 though.
quote:
2) Complining a java takes 5-10x longer than c/c++.
No it doesn''t. Typing "javac MyClass.java" may be 10 times slower, but:
1) javac is just *one* compiler.
2) If you try compiling 50 source files with one javac invocation you will see that it''s not all that slow. The slowness in compiling one file is in JVM startup, class loading, etc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement