Imagine your computer is like a kitchen. The CPU is the chef who prepares meals. What usually causes the chef to slow down the whole kitchen?
Think about what limits the chef's speed directly.
A CPU bottleneck happens when the processor has more work than it can handle at once, slowing down the entire system.
Consider this code that simulates a slow function by sleeping. What will be printed?
import time start = time.time() for _ in range(3): time.sleep(0.5) end = time.time() print(round(end - start, 1))
Each sleep lasts 0.5 seconds and runs 3 times.
The loop sleeps 0.5 seconds three times, totaling about 1.5 seconds.
You want to test that process_data() finishes in less than 2 seconds. Which assertion is correct?
import time start = time.time() process_data() end = time.time() # Which assertion below is correct?
Think about how to measure elapsed time.
Elapsed time is end minus start. It should be less than 2 seconds.
Look at this Python code that processes a list. What causes the slowdown?
data = list(range(100000)) result = [] for i in data: if i % 2 == 0: result.append(i) else: result.append(i*2) print(len(result))
Think about how Python handles list building efficiently.
Using a for-loop with append is slower than list comprehension for large lists.
You want to find slow database queries causing delays in your web application. Which tool helps best?
Focus on tools that measure performance, not code correctness.
A profiler that tracks SQL query times helps find slow queries causing bottlenecks.