adding flat profile result
This commit is contained in:
@@ -57,10 +57,24 @@ int main() {
|
||||
$ cat profile.txt
|
||||
```
|
||||
|
||||
## Understanding the Output
|
||||
## Understanding the Output (in the profile.txt file)
|
||||
- **Flat Profile**: Shows execution time spent in each function.
|
||||
- **Call Graph**: Displays function call relationships and their execution time.
|
||||
|
||||
The profiling results show that heavyComputation() takes significantly more execution time than lightComputation(), even though lightComputation() is called 1000 times.
|
||||
The flat profile from gprof also indicates the percentage of time spent in each function, helping to identify bottlenecks. For the above test program, the flat profile is like this:
|
||||
|
||||
```plaintext
|
||||
Each sample counts as 0.01 seconds.
|
||||
% cumulative self self total
|
||||
time seconds seconds calls ms/call ms/call name
|
||||
85.71 0.24 0.24 1 240.00 240.00 heavyComputation()
|
||||
14.29 0.28 0.04 1000 0.04 0.04 lightComputation()
|
||||
0.00 0.28 0.00 1 0.00 0.00 __static_initialization_and_destruction_0(int, int)
|
||||
```
|
||||
|
||||
Note: The __static_initialization_and_destruction_0(int, int) function is generated by the compiler during the static initialization and destruction phases of a program, particularly for global or static variables.
|
||||
|
||||
## Best Practices for Using `gprof`
|
||||
- Use `-O2` optimizations but **avoid `-O3`**, which may inline functions and reduce profiling accuracy.
|
||||
- Profile with realistic input data to get meaningful results.
|
||||
|
||||
Reference in New Issue
Block a user