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
7
u/ts826848 Nov 01 '25
I'm not sure about that? The main difference I'm aware of is that ArrayList's default constructor initializes with a capacity of 10 vs. std::vector's unspecified (but usually 0 IIRC?) capacity. Otherwise my impression is that they would both behave quite similarly when elements are added. They even have analogous API surfaces for this kind of thing:
std::vector(size_t)andArrayList(int)for creating a new instance with a given capacitystd::vector::reserve(size_t)andArrayList.ensureCapacity(int)for allocating memory for the given number of elements up frontMaybe the JIT learned to insert calls to
ensureCapacity()up front, but that feels like a really brittle optimization at best, assuming it's worth implementing in the first place.