Profile Guided Optimization
Profile Guided Optimization
# Compile with flag -fprofile-generate
gcc -omain main.c -O3 -fprofile-generate=<dir>
# Generate profile for the execution
./main
# Use the generated profile to optimize the binary
gcc -omain main.c -O3 -fprofile-use=<dir>
Note: The profiling build is run on multiple inputs to generate a profile that resembles the actual workload. Coverage with
gprof
is used to help with this step
Further Reading
- Parallel Programming and PGO with GCC
- Building GCC with PGO
- PGO in Chrome
- GCC PGO on IBM AIX to improve zstd