Skip to content

Instantly share code, notes, and snippets.

@dapangmao
Last active August 29, 2015 14:25
Show Gist options
  • Save dapangmao/17a03c4eb9b8c41baafb to your computer and use it in GitHub Desktop.
Save dapangmao/17a03c4eb9b8c41baafb to your computer and use it in GitHub Desktop.
from time import time
from concurrent.futures import ProcessPoolExecutor
def gcd(pair):
a, b = pair
low = min(a, b)
for i in range(low, 0, -1):
if a % i == 0 and b % i == 0:
return i
numbers = [(1963309, 2265973), (2030677, 3814172),
(1551645, 2229620), (2039045, 2020802)]
if __name__ == "__main__":
start = time()
results = list(map(gcd, numbers))
end = time()
print('Took %.3f seconds' % (end - start))
start = time()
pool = ProcessPoolExecutor(max_workers = 2) # The one change
results = list(pool.map(gcd, numbers))
end = time()
print('Took %.3f seconds' % (end - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment