Advertisement

C/C++ vs. Java - a simple speed test.

Started by March 31, 2001 06:00 AM
34 comments, last by nils_h 23 years, 10 months ago
LOL
I love these "x is faster than y" arguments!

I can''t believe how many people get on here claiming such things when they test, say, a bubble sort. Yea. Wow. We all certainly need the fastest bubble sorts--after all, that''s why we use bubble sorts in the first place, right?!

The truth of the matter is that most of the responses in here are correct; the comparison was actually testing the difference in efficiency of the Java compiler/VM and the C/C++ compiler, not the language.

Just like everything, every language has its forte. Even if Java were faster than C, Java is still not the right choice to make a Quake III engine, and expect it to run as quickly as a C version would--indeed this goes more into comparing APIs than the language, but I''m comparing overall usefulness at the moment. It''s a similar argument to that Linux may be 1000x better an operating system than Windows, but Windows still has more good applications than Linux does, overall making Windows more useful--unless, of course, you need a bulletproof server. So, again, everything has its place.

And, you know, if Java really were faster in more than just a simple bubble sort, don''t you think more developers would be using it for big things?

If you think about it, it''s extremely difficult to make interpreted code exactly as fast as native code. I think most will agree with me that this an immutable truth.

I understand that the test was to use the same code. But is that really fair to both languages? I think a more conclusive test would to write the fastest possible Java implementation, then write the fastest possible C implementation (no assembly, of course). Compare those. There are things in C you can never do in Java, and I honestly think that such things will make the difference.
QUOTE
And, you know, if Java really were faster in more than just a simple bubble sort, don''t you think more developers would be using it for big things?
/QUOTE

You obiosly don''t have a clue. Let me explain again: This test was only a random test to see that java is competeable with C. It could have been anything - 3D graphics to counting big primenumbers.

Most C/C++ developers are not aware of the possibilities of Java, and think it is "deadly slow", which it isn''t.

QUOTE
If you think about it, it''s extremely difficult to make interpreted code exactly as fast as native code. I think most will agree with me that this an immutable truth.
/QUOTE

Java is interpreted code- EHHHH???(!)
NO. Java is _compiled_ code. Not machinecode thought, but byte-compiled code. Java use hotspot technologies therefor Java is faster than ie C/C++ in many cases.

QUOTE
I understand that the test was to use the same code. But is that really fair to both languages? I think a more conclusive test would to write the fastest possible Java implementation, then write the fastest possible C implementation (no assembly, of course). Compare those. There are things in C you can never do in Java, and I honestly think that such things will make the difference.
/QUOTE

First- java standard API has a fast built-in sortmethod.
The java API is very nice and complete to work with. And again - it depends completly of what you are programming and how much time you have.
Advertisement
Ok, lets talk about REAL-WORLD here.

Existing product on the market. GUI was written in Java for portability. Internals were written in C/C++ for PERFORMANCE.

And this isn''t a small package, it is a large scale application to do white box testing of source code. (That should really narrow it down for people who wonder what the package is)

You obiosly don''t have a clue. Let me explain again: This test was only a random test to see that java is competeable with C. It could have been anything - 3D graphics to counting big primenumbers.


Anyone with half a brain will admit that Java can compete. That''s not so much the issue. But you were basically asking for it by coming onto here--a board mostly made up of C and C++ programmers--claiming that Java was obviously faster.


Java is interpreted code- EHHHH???(!)
NO. Java is _compiled_ code. Not machinecode thought, but byte-compiled code. Java use hotspot technologies therefor Java is faster than ie C/C++ in many cases.


It doesn''t matter if it''s byte compiled or done in the style of the old BASIC with line numbers. The point is that the code is not native code, therefore it''s interpreted in some sense since there is a translation somewhere.


First- java standard API has a fast built-in sortmethod.
The java API is very nice and complete to work with. And again - it depends completly of what you are programming and how much time you have.


Both C and C++ have sorting functions as part of their standard libraries--more so with C++, of course. And, yes, I agree 100% that whatever you use is a choice that should be dictated by time, resources, etc. since what''s "better" is what''s "better" for what you''re trying to do. And that''s what people need to remember a lot more often before they ask, say, whether to use Direct3D or OpenGL.
This discussion is pretty stupid !
I use both C and Java. I like Java because it is extremely easy to do pretty advanced networking stuff with little effort. I like C because it has a true connection to the hardware in a sence, and of course, you can handle the memory, also gets rid of those bloody classes which isn''t always a good thing. I like assembly because you can actually get the processor to do EXACLY what you ask of it. Also don''t forget the built in and unbelivably nice way of dealing with searching for strings in PERL, I really miss that in the other languages sometimes...


The only language i find quite annoying is VB/VBS, haven''t used it much though, just some asp - will never do that again... and that also applies to lotusscript - I will never try that again either...
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
Unless I''m misunderstanding what JIT means, Java is a compiled language. The only problem is that it is compiled at run time. That means that Java programs take an unhealthy amount of time at startup.

Just take a look at Forte4Java (written by Sun). It is SLOW. I''ve said this before and I''ll say it again. Forte4Java takes about a minute to load on my computer while MSVC 6.0 takes just over 5 seconds. It''s a Celeron 433 with 128 megs.

Even if Java is a wee bit faster than C, the long time it takes at startup will give the user an impression that it''s slow. To be fair though, JBuilder4 seems to be quite responsive and it makes me wonder whether applications written purely in JAVA will soon become common place.

And how do you know that automatic GC isn''t a major cause of slow down? You''re simple test didn''t use any memory allocatted from the heap so there is no use of the GC at all. The Boehm-Demers-Weiser Garbage Collector for C/C++ is probably the best GC for C/C++ programs, yet it does result in a significant slowdown in C/C++ applications. Memory allocations and deallocations take over 2 - 3 times as long (tested under lcc-win32 which conveniently comes with the library). Before you go knocking the authors of the library as incompetent twits, I suggest that you go look up who these guys are.

It is really unfair if you say that C/C++ programmers aren''t aware of the possibilities with Java. Many do. In fact, the C/C++ Users Journal comes with a pullout on code snippets in Java. It is in fact more accurate to say that most Java programmers aren''t aware of how to use their C/C++ compiler properly. Heck, most C/C++ programmers aren''t even sure of what their compilers are capable off. Different compiler flags will produce results that are really varied. That is a draw back of C/C++. Just check out the article that I posted a link to.

Java has its plus points. C++ has its plus points. They were designed for different things. If they weren''t, explain to me why Java is practically dead on the client side while it lives happily on the server side?
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Advertisement
for me the biggest problem with Java is it''s total lack of portability
LOL

Now as for this whole Java vs. C vs. C++ vs. ASM vs. Haskell vs. Oberon (and so on...) debate: Who cares! Use whatever language you want. There is no "best" language.

~~~~~~~~~~
Martee
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
I dont think its a matter of speed nowadays with 1ghrz+ processors becomming easily avalible on the morket

Im sticking with C++ for one reason and one reason only:

Its the language Im comfortable with.

Until another language comes along that I ''like'' - or if Im forced to switch languages (like what microsoft is going to force us to do with C#) - Im going to stick with c++

If I were more comfortable with Java, I might program more often with it, but until I reach that stage, c++ it my language of choise.

--LordKaT


Resist Windows XP''s Invasive Production Activation Technology!
Actually I think that Microsoft intends C# to replace Java, not C/C++. You notice that they decide to make a new internet oriented language as soon as they have a falling out with Sun...

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/

This topic is closed to new replies.

Advertisement