ARITHMETIC WORKSHEETS

Checking an ideal pipeline’s first result and final completion

A pipeline takes a full pass of stage time to produce its first result, then one result per stage time after that. Both numbers matter when you estimate a total.

Two numbers that people confuse

A pipeline has a latency and a throughput. Latency is how long a single item takes from start to finish. Throughput is how often finished items come out once the line is running. In an ideal pipeline of four one-unit stages, the first item takes 4 units, because it must pass every stage. After that, a finished item appears every unit, since the stages work on different items at once. Mixing the two leads to errors in both directions: assuming the line produces an item per unit from the very start, or assuming every item takes 4 units after the previous one.

Ten items through four stages

The worksheet uses four stages of one time unit each and ten items. The first item finishes at time 4. Each of the other nine finishes one unit after its predecessor, so the last one finishes at 4 plus 9, which the basic calculator gives as 13. Written as a formula, the completion time is the number of stages plus the number of items minus one. The stage count appears once, as the fill time, and the item count enters through the nine gaps between ten items. Both pieces must be present, and neither is multiplied by the other.

The serial alternative

Without overlap, each item would pass through all four stages before the next one started. Each item takes 4 units, and ten items take 4 times 10, which is 40 units. The pipeline finishes in 13 units. Dividing 40 by 13 gives a speedup of about 3.08, which is below the stage count of 4. The speedup approaches 4 only as the number of items grows. With a hundred items, the pipeline takes 4 plus 99, or 103 units, against 400 serially, a ratio of about 3.88. The fill time is a fixed cost, and its share of the total shrinks as the job gets longer.

Five stages and a hundred items

Another case keeps the structure and changes the numbers. With five stages of one unit and 100 items, the first item finishes at time 5 and the last at 5 plus 99, which is 104. A serial arrangement would need 5 times 100, which is 500. The classic five-stage processor pipeline from computer architecture textbooks, with fetch, decode, execute, memory access and write-back, follows the same arithmetic in an ideal case: 100 instructions take 104 cycles, close to one cycle each. Real processors lose cycles to hazards and stalls, which this model leaves out.

What the ideal model assumes

The calculation assumes every stage takes the same time, that each stage can hold a different item at once, that items are always available to start, and that buffers between stages add no delay. If any of these fail, the formula no longer holds. A stage that must wait for a result from a later stage, a machine that breaks down, or a queue that fills and blocks the stage behind it all change the completion time. The worksheet is about the arithmetic of an idealized line, and it makes no promise about any particular production or computing system.

Unequal stage times as an extension

If the stages take different times, the slowest stage sets the spacing between finished items, as a bottleneck. For illustration, take stages of 2, 1, 3 and 1 units with ten items and unlimited buffers between stages. The first item takes 2 plus 1 plus 3 plus 1, which is 7 units. The spacing is the slowest stage, 3 units, so nine more items add 27 units, for a finish at 34. This extension is outside the equal-stage example of the worksheet, but it shows why the formula changes: throughput follows the slowest stage, while the fill time follows the sum of all stages.

How busy each stage is

Utilization compares the time a stage spends working with the time the job lasts. In the ten-item example, each stage works for 10 units, one per item, while the job lasts 13 units. Each stage is therefore busy for 10 of 13 units, about 77 percent of the time. The idle time is the fill period at the start, when later stages wait for work, and the drain period at the end, when early stages have nothing left to do. With a hundred items the same stage works 100 of 103 units, about 97 percent. Utilization rises with batch size for the same reason the speedup does, and short jobs waste a larger share of the line.

Reading the result in practice

The completion time of 13 is the time of the last item, measured from the start of the first stage. If you want the average time per item, 13 divided by 10 gives 1.3 units, a figure that falls toward 1 as more items pass through. The latency of the first item, 4 units, does not improve with pipelining. A pipeline helps total throughput for a batch, and does nothing for the delay seen by one item. For an interactive task where one result is needed quickly, a longer pipeline can actually be worse if each stage adds handoff overhead.

Checking your own numbers

To check an estimate, split it into the two parts. The fill time is the sum of the stage durations for one item. The steady part is the spacing times the number of remaining items. Write both down before adding them. If an estimate equals the stage count times the item count, the overlap has been ignored, and if it equals only the item count, the fill time has been forgotten. For the 4 stages and 10 items of the worksheet, both mistakes are easy to catch: 40 is too large, and 10 is too small, since even the first item needs 4 units. Sketching a small timeline helps. Draw one row per stage and one column per time unit, and write the item number in each cell where it is being processed. Item 1 occupies the first stage in column 1, the second stage in column 2, and so on. Item 2 starts one column later. The last item reaches the last stage in column 13, and counting columns gives the same total as the formula without any algebra.

Reproduce the checks

Last-item completion

Open the Basic calculator and enter:

First number
4
Operation
add
Second number
9

Expected output:

Result

13

Nine subsequent spacings follow the first completion.

Summed stage work

Open the Basic calculator and enter:

First number
4
Operation
multiply
Second number
10

Expected output:

Result

40

Total work differs from the overlapped completion time.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Related tasks