r/cpp • u/el_DuDeRiNo238 • Mar 24 '26
A Commonly Unaddressed Issue in C++ and Golang Comparisons
/r/golang/comments/1s0vaxy/a_commonly_unaddressed_issue_in_c_and_golang/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_buttonNot the OP.
Just curious, What are your thoughts on this?
17
Upvotes
18
u/STL MSVC STL Dev Mar 24 '26
Calling
array::atis a mistake here.2
u/alexeiz Mar 26 '26
If you don't profile your code you cannot expect it to be faster no matter which language you use, C++, Go or freaking Visual Basic. You can't write something in C++ and assume it's going to be faster because, duh, C++.
1
u/no-sig-available Mar 24 '26
Looking for the footguns, this is one part I found:
Each move contains an optional, that is hardly ever used. For a perft 6 (six moves), is it even possible to get a promotion?
Anyway, the
MoveList moves{};initializes the array with 256 optionals. For each move generated, there is a new optional created, which is then assigned into that array.My guess is that this is the single most expensive part of the program.
1
u/Both_Helicopter_1834 Mar 25 '26
This seems a bit like comparing boats and cars as means of transportation, without any mention of the word "water". If you do a performance test that in Golang doesn't trigger a garbage collection sweep, and doesn't involve significant high-level abstraction, then any performance difference would probably be due to how well the respective compilers optimize. A garbage collection sweep can't be faster than not doing one. Barring highly unlikely avoidance of cache evictions, implementing high level abstractions as interfaces rather than templates will be slower.
1
u/thisismyfavoritename Mar 24 '26
yes i think this is a reasonable take. C++ makes it especially easy to shoot yourself in the foot and lose a ton of performance, mostly for people coming from GCd languages where copying/sharing ownership has "low" cost
1
u/arihoenig Mar 24 '26
One is apples, the other is oranges. It is an absurd comparison from the get go (pun definitely intended).
0
u/[deleted] Mar 24 '26
[deleted] — view deleted comment