Editor

Calculate the Speedup

Intermediate · Write the code · from Parallel and Distributed Computing: Speedup and Its Limits

From the lesson: How long do sequential and parallel solutions take?

A sequential solution takes as long as the sum of all of its steps. A parallel solution has two kinds of work. A parallel solution always consists of a parallel portion, the tasks that can run at the same time, and a sequential portion, the tasks that cannot. A photo-editing app shows both.

Read this part of the lesson

Write speedup(sequential_tasks, parallel_tasks). Doing every task one after another gives the sequential time; running the parallel tasks at the same time, each on its own processor, gives the parallel time. Return the sequential time divided by the parallel time, rounded to 2 decimal places. parallel_tasks always has at least one task.

speedup([10], [30, 30, 30])  ->  2.5   (100 / 40)
def speedup(sequential_tasks, parallel_tasks):
# Work out both times, then divide
pass

What Check runs

Your code runs first, then each of these lines, and 1 more that stay hidden. The output must match exactly.

RunsExpected output
print(speedup([10], [30, 30, 30]))2.5
print(speedup([], [20, 20, 20, 20]))4.0
print(speedup([5, 5], [40]))1.0

More Parallel Computing exercises

All Python exercises · 50 practice problems