Last active
October 28, 2021 14:43
-
-
Save 4sushi/93bfdd6e10a65ba63d076e92b9fe39ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from multiprocessing import Pool | |
import time | |
def get_url(url): | |
result = requests.get(url, params={}) | |
return url | |
if __name__ == '__main__': | |
urls = ['https://www.google.com/', 'https://foursquare.com/', 'https://www.yahoo.com/', 'https://www.bing.com/', "https://www.yelp.com/"] | |
t = time.time() | |
with Pool(5) as p: | |
res= p.map(get_url, urls) | |
for url in res: | |
print(url) | |
print("Time with pool processing: {:.3}s".format(time.time() - t) ) | |
t = time.time() | |
for url in urls: | |
result = get_url(url) | |
print(result) | |
print("Time sequential processing: {:.3}s".format(time.time() - t) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment