Last active
December 10, 2021 14:34
-
-
Save gdacciaro/d4c52b34f828996cbdfb8e5a72a17351 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 multiprocessing as mp | |
import numpy as np | |
import time | |
class CorsaDiCagnolini: | |
def __init__(self): | |
self.pool = mp.Pool(mp.cpu_count()) | |
def launcher(self): | |
start_time = time.time() | |
data = list() | |
data.append("🦮") | |
data.append("🐶") | |
data.append("🐺") | |
data.append("🐩") | |
results = self.pool.map(self.funzione_pesante_assaij,[row for row in data]) | |
self.pool.close() | |
print(results) | |
print("Winner >",data[np.argmin(results)],"<") | |
print("THE END: ", np.round(time.time() - start_time, 6), "sec") | |
pass | |
@staticmethod | |
def funzione_pesante_assaij(una_variabile): | |
print("start:", una_variabile) | |
start_time = time.time() | |
for i in range(10000): | |
for j in range(10000): | |
cinque = 2+2 | |
result = np.round(time.time() - start_time, 6) | |
print("end:", una_variabile , " ", result, "sec") | |
return result | |
if __name__ == '__main__': | |
print("Number of processors: ", mp.cpu_count()) | |
CorsaDiCagnolini().launcher() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment