Skip to content


C++ vs Java vs Python vs Ruby

I tend to be someone who is more pragmatic about using the right tool for the job rather than being language agnostic, so I found this overview on C++ vs Java vs Python vs Ruby (via Jake) to be an interesting comparison. However both Rod and I agree that the typical “Java is slower than C++” argument to mostly be a fallacy.

Posted in A Day In The Life Of, ColdFusion, Java, Python, Ruby, Tech News, Tips, Hacks, & Tricks, Uncategorized.

3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. I think the misconception comes from the fact that when you run a Java desktop application, it’s always slower than a native one, so people have a lot of real world experience observing Java being slower than C++.

    If the JVM was always resident in memory, however, this wouldn’t be quite so stark of a difference.

    The key difference is that, the longer a Java app runs, the faster it gets, because the JVM is actively monitoring the application, finding bottlenecks, and optimizing code as it runs. It also optimizies when to perform memory management functions. With enough time, the Java app becomes more effecient than most C++ applications, and can frequently outperform them.

    If you just start an application, let it run one time, and shut it down, it’s going to be far slower than C++. Java is completely wrong for quick scripting, and it definitely has drawbacks when dealing with desktop software. For servers and other long-running apps, however, Java is excellent.

  2. Zac McCormick said

    The term “faster” needs to be defined better I think to come to a conclusion. I can write an O(n^2) algorithm in language X, and then turn around and write a O(log n) algorithm in language Y and say that language Y is faster. So in that respect, you have to compare apples to apples, and it’s almost impossible to do (even with algorith complexity remaining constant).

    While I think Java might be pretty fast compared to other high level languages (perl/python/ruby), the facts speak for themselves when comparing it to C++. Look at performance intensive software out there (games, operating systems), and how much of it is done in Java? I think comparing the 2 in terms of performance really doesn’t make sense for this reason: the places where performance truly matters, you will never find a JVM. For example, kernel level code and other performance critical components of operating systems, you couldn’t use Java even if you wanted to. Games… every single game I’ve seen that runs on Java replaces the previous one on the “slowest game I’ve ever seen” list. Java has it’s own problem domain that (luckily for Java) doesn’t include performance critical applications.

    I just don’t see why Java fans have a chip on their shoulder when people say Java is ON AVERAGE slower than equivalent C++. How could it be any other way? One has an entire runtime management system, one doesn’t. Runtime management system = CPU ticks. Even if Java does runtime analyzation of the execution of a program, that burns CPU ticks also. Not to mention the fact that C++ is so powerful someone could create a runtime analyzation engine for their C++ application that modified itself just the way you are describing the way the JVM does it. We have to lay some ground rules if we are going to compare execution performance, and using a generational execution analyzer is cheating :P When it comes down to it, C++ applications just plain get more CPU ticks to use (the ones the JVM would be using). That being said, does the JVM use those lost CPU ticks more efficiently than the application itself would have used them? I know some C++ hackers who would say no :)

    I don’t think Hello World classes like the ones used in this performance comparison are a good way to compare these 2 technologies. The Java team has probably gone to GREAT lengths to optimize the emitted x86 code for those ridiculously simple operations. In my experience dealing with Java technology (I’m speaking about non-trivial applications where a GUI was created using Java), it is slow-as-hell. Every *real-world* java application I have used suffers horrible performance problems, not just during initialization either. The entire UI is sluggish and unresponsive.

    I’m bias towards C++ because I am super technical, and don’t like taking shortcuts when I can put in a little extra work to achieve a more efficient result. I also don’t hate Java, I respect its place and problem domain the world of computer programming. Java has a lot of advantages over C++, but performance cannot possibly be one of them.

  3. Rob said

    I just have a quick question, me and some friends have started to program/desighn a little game, and it just occured to me if im even using the right tool…im using python, what would be best for programing any pc game. Java, python, C++, or Ruby?

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.