Go and C++ side by side
Each of these pages takes one task, writes it in C++ and in Go, builds both with the real compilers and
shows the two runs next to each other. Then it says what differs and what that difference costs:
memory, errors, compilation, speed, and the people who maintain the code.
The numbers on the pages that measure something come from this machine, an Intel Core i3-6006U with
four hardware threads, and every page names the compiler versions it used. Where a tool is not
installed in the container, the page says so instead of showing output it did not produce.
Read one page when its topic comes up in your work, and follow the links into the
Go course and the C++ course for the full
lesson.
.cpp
Memory: the collector and RAII
A destructor that runs at the end of a scope against Close and defer, and a finalizer that delays collection by one cycle.
Open →
.cpp
Errors: returned values and exceptions
std::stoi throwing against an error return, a wrapped Go error, and the uncaught exception that kills the process.
Open →
.cpp
Generics and templates
One sum for two numeric types in both languages, a concept against a constraint, and the error each compiler gives for a wrong type.
Open →
.cpp
Concurrency: goroutines and threads
The same four-way parallel sum in both languages, the same 200 ms, and the race report each toolchain produces.
Open →
.cpp
Build and dependencies
CMake and make against go.mod and go build, a static binary against dynamic libraries, and what one new dependency costs.
Open →
.cpp
Testing: go test and CTest
A CHECK macro and a table test, ctest against go test, and the assert that disappears under NDEBUG.
Open →
.cpp
Binary size and startup
The bytes of a hello world and of a small JSON program in both languages, and the time each one takes to print a line.
Open →
.cpp
Performance: measured, not assumed
Sorting, hashing and parsing the same data in both languages, with the flags shown and the numbers from this machine.
Open →
.cpp
Refactoring
Renaming a field and changing a signature in both languages: what each compiler catches, and the rewrites a tool does for you.
Open →
.cpp
Tooling
Formatter, vet, documentation, debugger and profiler in both languages, and which of them are already installed.
Open →
.cpp
Onboarding: reading code you did not write
The same small program read cold in both languages, and the questions a newcomer has to answer before changing it.
Open →
.cpp
Maintainability over years
API and ABI stability, dependency drift and a two-year-old checkout, with the builds that prove the difference.
Open →
.cpp
When Go instead of C++, and when not
CLIs, build tools, data pipelines, network tools and teams with turnover against hard real time, SIMD and an existing C++ codebase.
Open →
A decision, not a score
The two languages overlap where a program is a process that reads input, computes and writes output,
and they hardly overlap anywhere else. Go is at its best in network services, command line tools and
the tooling around a build, where the code changes often and a team changes with it. C++ is at its
best where the program owns the machine: a game engine, a database kernel, a codec, a trading system
or a device driver, and where a pause of one millisecond is a defect.
When Go instead of C++, and when not draws that line with
the numbers the other pages measured. It is the last page of the group and the shortest answer to the
question that brought a reader here.
The C++ programs of this group were built with g++ 15.2.0 (Alpine 15.2.0) and CMake 4.2.3, and the Go
programs with go 1.26.10; all were run on Alpine
Linux 3.24.3 (x86_64) in a Docker container on an
Intel Core i3-6006U with four hardware threads.