Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nekoma Tech
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chevalier Paul
Nekoma Tech
Commits
e7b70717
Commit
e7b70717
authored
3 weeks ago
by
Paul Chevalier
Browse files
Options
Downloads
Patches
Plain Diff
multi
parent
b3ba2497
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
multithreading.py
+29
-0
29 additions, 0 deletions
multithreading.py
with
29 additions
and
0 deletions
multithreading.py
0 → 100644
+
29
−
0
View file @
e7b70717
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
:
.
2
f
}
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
:
.
2
f
}
secondes
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment