Java vs C++ Performance
Cluster centers on debates about Java's runtime performance, speed, memory usage, startup time, and JIT optimizations compared to C/C++, Rust, and other native languages, challenging myths of Java's inherent slowness.
Activity Over Time
Top Contributors
Keywords
Sample Comments
What's the reasoning behind picking Java for a performance critical application over something like C or C++?
Java is fast enough now to compete with C++ in some categories of software traditionally viewed as "high performance" e.g. web-servers or database systems. Applications running like "turtle on anything short of server-class hardware" is a result of bad-coding, not Java itself.
> Java is slow and bloated compared to native.What do you mean by "native"? C/C++? Yes, given enough effort you can write C code that outperforms Java code, sometimes handily, especially in single threaded or low-contention cases. Yet we did write applications in C/C++ before we switched to Java, we had excellent reasons to make the switch, and there have been precious few companies making the switch back. That shows you that the microbenchmarks don't tell
Most programs don't need C++ performance. Java is usually within factor of two and usually fast enough.
The only thing slow about java is the time to start the jvm.For everything else to be faster you need asm, c, c++, fortran, or rust.Loading an applet over a modem in 1998 doesn't count...
For Java that's mostly a myth. Modern Java isn't measurably slower than C++ in many cases and faster in some.
jvm is really fast, it can usually compete with C++ code in terms of speed (if you ignore the startup time ;p )
Java is fast but takes 5x-10x memory that a proper AOTC language app.
In particular areas (short timespans, specific tasks), Java can be thousands of times slower than C++/Rust. (Warmup/pre-JIT function evaluation, GC pauses, etc.) I have these kinds of performance rough spots, but I'm surprised to hear you do. It doesn't seem consistent with an argument for Java.
Java does not provide performance comparable to C/C++.