In this section, we will look at the results of Amdahl's Law through a Python program. Still considering the task of determining whether an integer is a prime number, as discussed in Chapter 1, Advanced Introduction to Concurrent and Parallel Programming, we will see what actual speedup is achieved through concurrency. If you already have the code for the book downloaded from the GitHub page, we are looking at the Chapter02/example1.py file.
As a refresher, the function that checks for prime numbers is as follows:
# Chapter02/example1.py
from math import sqrt
def is_prime(x):
if x < 2:
return False
if x == 2:
return x
if x % 2 == 0:
return False
limit = int(sqrt(x)) + 1
for i in range(3, limit, 2):
if x % i == 0:
return False
return x
The next part of the code is a function that takes in an...