AlgoMaster Logo
AlgoMasterCalculate Amdahl's Law Speedupeasy

Calculate Amdahl's Law Speedup

easy

Adding processors does not make a fixed workload proportionally faster when some of its work must remain serial. Amdahl's Law quantifies that limit.

Design an AmdahlSpeedupCalculator class:

  • AmdahlSpeedupCalculator() creates a stateless calculator.
  • double speedup(double parallelFraction, int processors) returns the speedup over one processor, rounded to 5 decimal places.

Treat the original runtime as 1:

  • The serial fraction is 1 - parallelFraction and does not speed up.
  • The parallel fraction takes parallelFraction / processors time.
  • The new runtime is (1 - parallelFraction) + parallelFraction / processors.
  • Speedup is 1 / newRuntime.

Round only the final speedup. Each call is independent and must not use values from an earlier call.

Example 1:

Input:

Output:

Explanation: The new runtime is 0.1 + 0.9 / 4 = 0.325. The speedup is 1 / 0.325 = 3.076923..., which rounds to 3.07692.

Example 2:

Input:

Output:

Explanation: The new runtime is 0.05 + 0.95 / 8 = 0.16875, so the workload is about 5.93 times faster rather than 8 times faster.

Constraints

  • 0 <= parallelFraction <= 1
  • 1 <= processors <= 10^6
  • Round the final answer to 5 decimal places.
  • Answers are accepted within 10^-5 of the expected result.
  • At most 100 calls are made to speedup.
Hints

Loading...
CallReturns
new AmdahlSpeedupCalculator()null
speedup(0.9, 4)3.07692

The new runtime is the 0.1 serial fraction plus 0.9 / 4 = 0.225 parallel time, or 0.325 total. Its reciprocal is 3.07692.

Run checks these cases. Submit also runs a larger hidden set.