Which of the following best explains why optimization reduces the time a program takes to run?
Think about how fewer instructions affect the CPU workload.
Optimization removes or simplifies instructions that do not affect the final result, so the CPU executes fewer steps, making the program faster.
Loop unrolling is a common optimization technique. What is its main effect on program performance?
Consider how loop control instructions affect the speed of repeated tasks.
Loop unrolling reduces the number of times the program checks loop conditions, which lowers overhead and speeds up execution.
Consider a program with some code that never runs (dead code). How does removing this dead code improve performance?
Think about what happens if the CPU executes instructions that do nothing useful.
Removing dead code means the CPU skips instructions that do not affect the program, reducing execution time and memory use.
Why does inlining a small function often improve program performance compared to calling the function normally?
Consider what happens each time a function is called.
Inlining inserts the function's code directly where it is called, so the program avoids the time spent jumping to and returning from the function.
Register allocation is an optimization that assigns variables to CPU registers instead of memory. Why does this improve program speed?
Think about the difference in speed between CPU registers and main memory.
CPU registers are the fastest storage locations for data. Using them reduces the time needed to read or write variables, speeding up the program.