Stimulus process with wait statements in VHDL - Time & Space Complexity
When we use wait statements in a VHDL stimulus process, we want to understand how the time the process takes grows as we add more wait steps.
We ask: How does adding more wait statements affect the total execution time?
Analyze the time complexity of the following code snippet.
process
begin
signal_a <= '1';
wait for 10 ns;
signal_a <= '0';
wait for 10 ns;
signal_a <= '1';
wait for 10 ns;
wait; -- end process
end process;
This process changes a signal and waits for fixed time intervals between changes.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Each wait for 10 ns statement pauses the process.
- How many times: The process has three wait statements executed sequentially.
Imagine we add more wait statements like these to the process.
| Input Size (number of wait steps) | Approx. Operations (waits) |
|---|---|
| 3 | 3 waits |
| 10 | 10 waits |
| 100 | 100 waits |
Pattern observation: The total wait time grows directly with the number of wait statements added.
Time Complexity: O(n)
This means the total execution time grows in a straight line as you add more wait steps.
[X] Wrong: "Adding more wait statements does not affect total execution time because the process just waits."
[OK] Correct: Each wait adds a fixed delay, so more waits add more total time, making the process take longer.
Understanding how wait statements affect timing helps you design testbenches and simulations that run efficiently and predictably.
"What if we replaced fixed wait times with conditional waits? How would that change the time complexity?"