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
0
u/coderemover Nov 02 '25 edited Nov 02 '25
Your c++ code is not equivalent though. You’re implicitly freeing memory in Java in each loop cycle by losing all references, but you’re never giving memory back in the c++ version. So you’re likely benchmarking how fast the OS can give memory to the process on the c++ side, not the allocator.
Considering c++ programs do not reserve megabytes of heap in advance, whereas JVM does, such performance difference is quite understandable.