Speed of Different Programming Languages

Started by
4 comments, last by EbonySeraph 22 years, 8 months ago
I know this should go in another section but I want as many replies as possible. Even if you see I reply that is just what you are going to say, please add what you may have more. This question is for a research project I am doing in school: What is the speed difference between C, C++, and Java? I mean in depth detail. I heard something in a post a while ago about C vs C++ and someone said something about C functions calls being faster. If anyone can explain why that would be greatly appreciated. Also if any one knows Java can someone tell me about why Java is slower than the other two languages. Also if you have any history(thought I have some) about the languages feel free to throw some in. Or if anyone knows a web site that has all the info or significantly chunked peices of it. Please tell me the URL. Thanks for your help. "Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
"Ogun's Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
Advertisement
The idea of researching things like this is that you either get proper data, or you measure it yourself, you don''t collect a load of opinions.

There is no reason why C function calls should be faster than C++ function calls. C++ member functions tend to be implemented by placing the ''this'' pointer in a register which may actually work out to be faster than the C equivalent of needing an extra parameter. Similarly, ''virtual function'' calls take longer than a normal function call, but that''s because they do more than a normal function call, so you''re not comparing like with like there. Also, although Java is theoretically slower than both C and C++ languages since it''s interpreted, good optimisation can often make it run as fast as compiled code anyway.

If you want to do this project properly, design some tests, and measure the results.
If you''re counting cycles then c functions might be slightly faster but if you''re not(most likely) then there''s no speed differences.

Now, Java is an interpreted language. That means instructions in the programs aren''t executed by the processor directly - they''re routed through the java interpreter first. Since they go through one at a time it''s fairly slow. There is a Java technology called JIT(Just In Time). What it does is it doesn''t run each instruction one at a time - it decodes batches of instructions at once. Therefore, java programs can actually be used for 2D games. It''s still not as fast as c/c++ but it''s actually usable now.

There''s even something called Java3D which lets you use 3D in java.
I have to agree with Kylotan since a "research project" implies that research be done on your part.

However, Java will tend to run slower than both C and C++, even when compiled into bytecode, as Java comes with additional features such as garbage collection and what not which will incur a performance hit.
It''s true that the "this" parameter in c++ is passed on a register, but that isn''t impossible to achieve in c. If you declare a function in c as __fastcall, it passes up to three parameters as registers. But if you''re counting cycles, you should be declaring functions as inline anyway.

In the end, you''ll never really notice any speed difference between c++ and c. Use whichever one you feel comfortable with.
Beyond that—to my knowledge—the language itself has no specifications on calling conventions, meaning that compilers can implement function calls however they see fit, including the use of registers. The same is true with C++.

This topic is closed to new replies.

Advertisement