1 Commits

Author SHA1 Message Date
Derqsi Bilal 54fb5a3c28 compte rendu tp1 2026-10-07 12:41:59 +02:00
5 changed files with 6217 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
Derqsi bilal
Pierre Courtehoux
Youness Boulalam
Mesurer / Profiler
Temps d'exécution et empreinte sans -pg
Empreinte du rapport : 1d53de903efd2b7c
L'empreinte permet de vérifier que l'exécution du programme retourne exactement le même résultat après les optimisations.
real 0m2.659s
user 0m2.637s
sys 0m0.004s
Profilage
La fonction la plus appelée est egales(), avec 308 701 874 appels, pour un temps d'exécution de 0,72 seconde.
La deuxième fonction qui consomme le plus de temps est longueur(), avec 36 009 819 appels, pour un temps d'exécution de 0,69 seconde.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
33.26 0.72 0.72 308701874 0.00 0.00 egales
31.42 1.41 0.69 36009819 0.00 0.00 longueur
14.68 1.73 0.32 150182 0.00 0.01 chercher_mot
Analyse
On peut voir qu'une grande partie du temps d'exécution, soit environ 80 %, est concentrée dans les trois fonctions egales(), longueur() et chercher_mot().
Cette consommation importante s'explique par le fait que ces fonctions sont très fréquemment utilisées.
Par exemple, egales() compare les caractères des chaînes un par un afin de déterminer si deux mots sont identiques. Elle est donc appelée un très grand nombre de fois.
On peut également constater que la majorité des appels à egales() provient de chercher_mot() :
296 656 203 / 308 701 874 appels
Cela montre que chercher_mot() est un point important à optimiser afin de réduire le nombre d'appels à egales() et d'obtenir un maximum de gain avec un minimum de modifications.
Optimisation 1 : réduire le nombre d'appels à egales()
Il n'est pas nécessairement possible d'améliorer significativement la fonction egales() elle-même, car son fonctionnement est déjà simple : elle parcourt les caractères des deux chaînes jusqu'à trouver une différence ou atteindre la fin.
En revanche, on peut réduire fortement le nombre de fois où cette fonction est appelée.
La fonction chercher_mot() effectue actuellement une recherche linéaire dans le tableau des mots. Pour chaque nouveau mot, elle compare celui-ci avec les mots déjà présents dans le tableau.
Une amélioration importante serait donc d'utiliser une table de hachage afin de retrouver directement le mot recherché, au lieu de parcourir successivement toutes les entrées.
Cette optimisation permettrait de réduire fortement le nombre d'appels à egales() et donc le temps d'exécution.
Optimisation 2 : calculer la moyenne une seule fois
Dans ecart_type_longueur(), la moyenne était recalculée à chaque itération de la boucle.
La moyenne ne change pourtant pas pendant cette boucle. Il est donc inutile de la recalculer plusieurs milliers de fois.
La fonction peut être modifiée ainsi :
double somme = 0.0;
double moyenne = longueur_moyenne(table, n);
for (int i = 0; i < n; i++) {
double ecart = longueur(table[i].mot) - moyenne;
somme += ecart * ecart;
}
return somme / n;
Cette modification permet de calculer la moyenne une seule fois, au lieu de la recalculer pour chaque mot.
Résultat après optimisation
L'empreinte du rapport reste identique :
Empreinte du rapport : 1d53de903efd2b7c
Cela confirme que le résultat du programme n'a pas été modifié par l'optimisation.
Après compilation avec :
gcc -O0 analyseur.c -o analyseur
et exécution avec :
time ./analyseur
on obtient :
real 0m2.107s
user 0m2.081s
sys 0m0.003s
Avant optimisation, le temps real était de 2,659 secondes. Après optimisation, il est de 2,107 secondes.
On obtient donc un gain d'environ 0,55 seconde, soit environ 21 % de réduction du temps d'exécution.
Executable
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+290
View File
@@ -0,0 +1,290 @@
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
34.47 0.76 0.76 36009819 0.00 0.00 longueur
31.96 1.46 0.70 308701874 0.00 0.00 egales
15.53 1.79 0.34 150182 0.00 0.01 chercher_mot
4.57 1.90 0.10 12172087 0.00 0.00 comparer
3.20 1.97 0.07 1 70.00 190.00 trier_entrees
2.74 2.02 0.06 5867 0.01 0.13 longueur_moyenne
2.28 2.08 0.05 _init
1.60 2.11 0.04 32667 0.00 0.00 copier
0.91 2.13 0.02 17202045 0.00 0.00 doit_echanger
0.91 2.15 0.02 250000 0.00 0.00 est_mot_vide
0.46 2.16 0.01 5297256 0.00 0.00 est_lettre
0.46 2.17 0.01 21746 0.00 0.05 compter_mots_ligne
0.46 2.18 0.01 1 10.00 17.09 analyser_bigrammes
0.46 2.19 0.01 1 10.00 10.00 decouper_lignes
0.00 2.19 0.00 1266663 0.00 0.00 en_minuscule
0.00 2.19 0.00 928117 0.00 0.00 alea
0.00 2.19 0.00 150182 0.00 0.01 compter_mot
0.00 2.19 0.00 26801 0.00 0.00 ajouter
0.00 2.19 0.00 21746 0.00 0.00 normaliser_ligne
0.00 2.19 0.00 1 0.00 6.41 construire_rapport
0.00 2.19 0.00 1 0.00 781.57 ecart_type_longueur
0.00 2.19 0.00 1 0.00 0.00 empreinte
0.00 2.19 0.00 1 0.00 0.00 generer_texte
0.00 2.19 0.00 1 0.00 22.87 generer_vocabulaire
0.00 2.19 0.00 1 0.00 0.00 racine
% the percentage of the total running time of the
time program used by this function.
cumulative a running sum of the number of seconds accounted
seconds for by this function and those listed above it.
self the number of seconds accounted for by this
seconds function alone. This is the major sort for this
listing.
calls the number of times this function was invoked, if
this function is profiled, else blank.
self the average number of milliseconds spent in this
ms/call function per call, if this function is profiled,
else blank.
total the average number of milliseconds spent in this
ms/call function and its descendents per call, if this
function is profiled, else blank.
name the name of the function. This is the minor sort
for this listing. The index shows the location of
the function in the gprof listing. If the index is
in parenthesis it shows where it would appear in
the gprof listing if it were to be printed.
Copyright (C) 2012-2026 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
Call graph (explanation follows)
granularity: each sample hit covers 4 byte(s) for 0.46% of 2.19 seconds
index % time self children called name
<spontaneous>
[1] 97.7 0.00 2.14 main [1]
0.01 1.07 21746/21746 compter_mots_ligne [2]
0.00 0.78 1/1 ecart_type_longueur [6]
0.07 0.12 1/1 trier_entrees [9]
0.00 0.04 21746/21746 normaliser_ligne [14]
0.00 0.02 1/1 generer_vocabulaire [17]
0.01 0.01 1/1 analyser_bigrammes [18]
0.01 0.00 1/1 decouper_lignes [20]
0.00 0.01 1/1 construire_rapport [21]
0.00 0.00 1/5867 longueur_moyenne [5]
0.00 0.00 1/1 generer_texte [25]
0.00 0.00 1/1 racine [26]
0.00 0.00 1/1 empreinte [24]
-----------------------------------------------
0.01 1.07 21746/21746 main [1]
[2] 49.1 0.01 1.07 21746 compter_mots_ligne [2]
0.00 1.02 150182/150182 compter_mot [3]
0.02 0.03 250000/250000 est_mot_vide [13]
-----------------------------------------------
0.00 1.02 150182/150182 compter_mots_ligne [2]
[3] 46.5 0.00 1.02 150182 compter_mot [3]
0.34 0.67 150182/150182 chercher_mot [4]
0.01 0.00 5866/32667 copier [15]
-----------------------------------------------
0.34 0.67 150182/150182 compter_mot [3]
[4] 46.2 0.34 0.67 150182 chercher_mot [4]
0.67 0.00 296656203/308701874 egales [8]
-----------------------------------------------
0.00 0.00 1/5867 main [1]
0.06 0.72 5866/5867 ecart_type_longueur [6]
[5] 35.7 0.06 0.72 5867 longueur_moyenne [5]
0.72 0.00 34415822/36009819 longueur [7]
-----------------------------------------------
0.00 0.78 1/1 main [1]
[6] 35.7 0.00 0.78 1 ecart_type_longueur [6]
0.06 0.72 5866/5867 longueur_moyenne [5]
0.00 0.00 5866/36009819 longueur [7]
-----------------------------------------------
0.00 0.00 5866/36009819 ecart_type_longueur [6]
0.00 0.00 26801/36009819 ajouter [16]
0.03 0.00 1561330/36009819 normaliser_ligne [14]
0.72 0.00 34415822/36009819 longueur_moyenne [5]
[7] 34.5 0.76 0.00 36009819 longueur [7]
-----------------------------------------------
0.03 0.00 12045671/308701874 est_mot_vide [13]
0.67 0.00 296656203/308701874 chercher_mot [4]
[8] 32.0 0.70 0.00 308701874 egales [8]
-----------------------------------------------
0.07 0.12 1/1 main [1]
[9] 8.7 0.07 0.12 1 trier_entrees [9]
0.02 0.10 17202045/17202045 doit_echanger [10]
-----------------------------------------------
0.02 0.10 17202045/17202045 trier_entrees [9]
[10] 5.5 0.02 0.10 17202045 doit_echanger [10]
0.10 0.00 12172087/12172087 comparer [11]
-----------------------------------------------
0.10 0.00 12172087/12172087 doit_echanger [10]
[11] 4.6 0.10 0.00 12172087 comparer [11]
-----------------------------------------------
<spontaneous>
[12] 2.3 0.05 0.00 _init [12]
-----------------------------------------------
0.02 0.03 250000/250000 compter_mots_ligne [2]
[13] 2.2 0.02 0.03 250000 est_mot_vide [13]
0.03 0.00 12045671/308701874 egales [8]
-----------------------------------------------
0.00 0.04 21746/21746 main [1]
[14] 1.6 0.00 0.04 21746 normaliser_ligne [14]
0.03 0.00 1561330/36009819 longueur [7]
0.00 0.00 1539584/5297256 est_lettre [19]
0.00 0.00 1266663/1266663 en_minuscule [22]
-----------------------------------------------
0.01 0.00 5866/32667 compter_mot [3]
0.03 0.00 26801/32667 ajouter [16]
[15] 1.6 0.04 0.00 32667 copier [15]
-----------------------------------------------
0.00 0.01 5867/26801 construire_rapport [21]
0.00 0.02 20934/26801 generer_vocabulaire [17]
[16] 1.3 0.00 0.03 26801 ajouter [16]
0.03 0.00 26801/32667 copier [15]
0.00 0.00 26801/36009819 longueur [7]
-----------------------------------------------
0.00 0.02 1/1 main [1]
[17] 1.0 0.00 0.02 1 generer_vocabulaire [17]
0.00 0.02 20934/26801 ajouter [16]
0.00 0.00 27934/928117 alea [23]
-----------------------------------------------
0.01 0.01 1/1 main [1]
[18] 0.8 0.01 0.01 1 analyser_bigrammes [18]
0.01 0.00 3757672/5297256 est_lettre [19]
-----------------------------------------------
0.00 0.00 1539584/5297256 normaliser_ligne [14]
0.01 0.00 3757672/5297256 analyser_bigrammes [18]
[19] 0.5 0.01 0.00 5297256 est_lettre [19]
-----------------------------------------------
0.01 0.00 1/1 main [1]
[20] 0.5 0.01 0.00 1 decouper_lignes [20]
-----------------------------------------------
0.00 0.01 1/1 main [1]
[21] 0.3 0.00 0.01 1 construire_rapport [21]
0.00 0.01 5867/26801 ajouter [16]
-----------------------------------------------
0.00 0.00 1266663/1266663 normaliser_ligne [14]
[22] 0.0 0.00 0.00 1266663 en_minuscule [22]
-----------------------------------------------
0.00 0.00 27934/928117 generer_vocabulaire [17]
0.00 0.00 900183/928117 generer_texte [25]
[23] 0.0 0.00 0.00 928117 alea [23]
-----------------------------------------------
0.00 0.00 1/1 main [1]
[24] 0.0 0.00 0.00 1 empreinte [24]
-----------------------------------------------
0.00 0.00 1/1 main [1]
[25] 0.0 0.00 0.00 1 generer_texte [25]
0.00 0.00 900183/928117 alea [23]
-----------------------------------------------
0.00 0.00 1/1 main [1]
[26] 0.0 0.00 0.00 1 racine [26]
-----------------------------------------------
This table describes the call tree of the program, and was sorted by
the total amount of time spent in each function and its children.
Each entry in this table consists of several lines. The line with the
index number at the left hand margin lists the current function.
The lines above it list the functions that called this function,
and the lines below it list the functions this one called.
This line lists:
index A unique number given to each element of the table.
Index numbers are sorted numerically.
The index number is printed next to every function name so
it is easier to look up where the function is in the table.
% time This is the percentage of the `total' time that was spent
in this function and its children. Note that due to
different viewpoints, functions excluded by options, etc,
these numbers will NOT add up to 100%.
self This is the total amount of time spent in this function.
children This is the total amount of time propagated into this
function by its children.
called This is the number of times the function was called.
If the function called itself recursively, the number
only includes non-recursive calls, and is followed by
a `+' and the number of recursive calls.
name The name of the current function. The index number is
printed after it. If the function is a member of a
cycle, the cycle number is printed between the
function's name and the index number.
For the function's parents, the fields have the following meanings:
self This is the amount of time that was propagated directly
from the function into this parent.
children This is the amount of time that was propagated from
the function's children into this parent.
called This is the number of times this parent called the
function `/' the total number of times the function
was called. Recursive calls to the function are not
included in the number after the `/'.
name This is the name of the parent. The parent's index
number is printed after it. If the parent is a
member of a cycle, the cycle number is printed between
the name and the index number.
If the parents of the function cannot be determined, the word
`<spontaneous>' is printed in the `name' field, and all the other
fields are blank.
For the function's children, the fields have the following meanings:
self This is the amount of time that was propagated directly
from the child into the function.
children This is the amount of time that was propagated from the
child's children to the function.
called This is the number of times the function called
this child `/' the total number of times the child
was called. Recursive calls by the child are not
listed in the number after the `/'.
name This is the name of the child. The child's index
number is printed after it. If the child is a
member of a cycle, the cycle number is printed
between the name and the index number.
If there are any cycles (circles) in the call graph, there is an
entry for the cycle-as-a-whole. This entry shows who called the
cycle (as parents) and the members of the cycle (as children.)
The `+' recursive calls entry shows the number of function calls that
were internal to the cycle, and the calls entry for each member shows,
for that member, how many times it was called from other members of
the cycle.
Copyright (C) 2012-2026 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
Index by function name
[12] _init [15] copier [25] generer_texte
[16] ajouter [20] decouper_lignes [17] generer_vocabulaire
[23] alea [10] doit_echanger [7] longueur
[18] analyser_bigrammes [6] ecart_type_longueur [5] longueur_moyenne
[4] chercher_mot [8] egales [14] normaliser_ligne
[11] comparer [24] empreinte [26] racine
[3] compter_mot [22] en_minuscule [9] trier_entrees
[2] compter_mots_ligne [19] est_lettre
[21] construire_rapport [13] est_mot_vide
+5867
View File
File diff suppressed because it is too large Load Diff