Profile Guided Optimization

Back

# 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

Case Studies