Speed of Different Programming Languages

Started by
15 comments, last by EbonySeraph 22 years, 8 months ago
Mmmrph. That was me as AP, above.
Advertisement
The ''this'' pointer is passed in the ECX register (not EBX) on intel (and compatible) platforms.
quote:Original post by CheeseGrater, masquerading as an Anonymous Poster
I recognize that passing in a structure causes an equal performance hit. When we used to voice that concern, what we were really complaining about was that encapsulation would cause additional overhead _when you only had one instance_.

When there''s one instance, there''s no extra information to pass, so you can globalize it and remove what was at the time a stack push/pop, and is now just a register move.

This is not a difference between the languages. This is a difference between object-oriented or well-structured code against global variables. You can do exactly the same in C++ if you want globals hanging around your code. In that case, you would use a static member function in C++, which is exactly equivalent to a function in C, which means they have equivalent execution time. On the other hand, if you don''t want globals, you would have to use one of the function syntaxes I showed above, which again, have equivalent execution time. The fact remains: to achieve the same task takes the same length of time in C++ as it does in C. There is no overhead.

PS. Dactylos is right: it''s actually the ECX register for the ''this'' pointer.
If there''s only one instance, the class can have all static methods and static properties, which means no this pointer is passed in ecx, saving you that extra mov, and should compile to identical asm as the C procedures operating on global variables. As mentioned, this all died with the 386 if not sooner.

I''ve yet to use a Java program that has acceptable performance. Imagine if Excel or Word was written in Java... it''d take 10 minutes to load, and 2 hours to recalculate. I know there are claims out there that Java programs can run just as fast as C++ programs, and even ''performance data'' that supports this. But I''ve never used a Java program that didn''t seem sluggish. The performance varies wildly depending on the JVM that''s used.

...
quote:
I can''t imagine anyone changing their class hierarchy to optimize one loop...

They''re usually abandoned if the design was that bad.

Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Just out of interest I think that Sun made a processor (called Pico?) that runs Java bytecode natively. In my opinion C++ is no slower that C, and if it is it is because the programmer wrote it slow. Virtual functions are about the only thing the slows C++ down (and it''s negliable). One could argue that C++''s inline methods speed it up compared to C (I don''t cause this is a programmer decision, but some might). In the old days it was slower, now it''s pretty good. Oh! Actually, if you use extensive exception throwing it will be a bit slower.

Brad
You might wanna check out:
http://www.ubka.uni-karlsruhe.de/cgi-bin/psview?document=ira/2000/5&format=1&page=13

You also might want to include Python in your research paper

"Journies Lead to Knowledge and Passion Lights the Way..."

~=NeuroMorphus=~
"Journies Lead to Knowledge and Passion Lights the Way..."~=NeuroMorphus=~
Also check out:

http://www-md.fsl.noaa.gov/~romberg/utest/hello.html

"Journies Lead to Knowledge and Passion Lights the Way..."

~=NeuroMorphus=~
"Journies Lead to Knowledge and Passion Lights the Way..."~=NeuroMorphus=~

This topic is closed to new replies.

Advertisement