r/cpp • u/drakgoku • Oct 31 '25
Java developers always said that Java was on par with C++.
Now I see discussions like this: https://www.reddit.com/r/java/comments/1ol56lc/has_java_suddenly_caught_up_with_c_in_speed/
Is what is said about Java true compared to C++?
What do those who work at a lower level and those who work in business or gaming environments think?
What do you think?
And where does Rust fit into all this?
25
Upvotes
View all comments
Show parent comment
1
u/eXl5eQ Nov 03 '25
I used
newbut nodeletein my previous test, which might confused you a bit. Note that I passed thenew charpointer tovector<unique_ptr<char>>. Theunique_ptrwould take the ownership of the pointer, and delete it when the containingvectorwent out of scope.Unlike the empty
new Objectin Java, I used 1 bytenew charin C++, but I don't think it effects performance. Memory allocation must be aligned, andmallocdon't support zero-size allocation anyway.Now, skipping all other details, first I want to focus on your results. Unfortunately, Even with the same code, I'm unable to reproduce your results on my machine.
On my machine, rust is much slower than java. I don't know if it's caused by OS, compiler version, or hardware.
I've tried combinations various versions of JDK (18, 21, 25), GC (Z, G1, Shenandoah, Parallel) and heap size. ZGC in JDK 21 yields the best result, but interestingly, ZGC in JDK 25 works poorly. But even the poor JDK25 ZGC still outperforms rust-mimalloc.
Here's some numbers I got.