How to simulate in Python

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 8, 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 Chapter09/example1.py file.

As a refresher, the function that checks for prime numbers is as follows:

# Chapter09/example1.pyfrom math import sqrtdef 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:

Get Advanced Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.