Skip to content
Snippets Groups Projects
Commit e7b70717 authored by Paul Chevalier's avatar Paul Chevalier
Browse files

multi

parent b3ba2497
No related branches found
No related tags found
No related merge requests found
import time
import threading
# Fonction simulant une tâche lourde (ex: traitement d'image, calculs intensifs)
def tache_lourde():
somme = 0
for _ in range(10**7): # Boucle qui prend un certain temps
somme += 1
return somme
# Exécution sans multithreading
start = time.time()
for _ in range(4): # Exécuter 4 tâches séquentiellement
tache_lourde()
end = time.time()
print(f"Temps sans multithreading: {end - start:.2f} secondes")
# Exécution avec multithreading
start = time.time()
threads = []
for _ in range(4): # Lancer 4 threads en parallèle
thread = threading.Thread(target=tache_lourde)
threads.append(thread)
thread.start()
for thread in threads:
thread.join() # Attendre que tous les threads finissent
end = time.time()
print(f"Temps avec multithreading: {end - start:.2f} secondes")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment