CentOS 下 C++ 性能优化实用指南
一 编译器与构建优化
sudo yum install centos-release-scl && sudo yum install devtoolset-11-gcc* && scl enable devtoolset-11 bash。二 代码层面的关键优化
三 系统级与运行时调优
四 性能分析与验证
五 一键可用的优化示例
g++ -O3 -march=native -flto -fdata-sections -ffunction-sections \
-fno-exceptions -fno-rtti \
-DNDEBUG \
main.cpp -o app -lpthread
strip --strip-unneeded app
g++ -O0 -g -DDEBUG \
main.cpp -o app_debug -lpthread
make -j$(nproc)
# 或 CMake
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -march=native -flto" ..
make -j$(nproc)
numactl --cpunodebind=0 --membind=0 ./app
taskset -c 0-3 ./app