This commit is contained in:
2025-09-10 17:10:03 +02:00
parent ca552281c9
commit 2613a9beb3
5 changed files with 29 additions and 3 deletions

26
Rapport.txt Normal file
View File

@@ -0,0 +1,26 @@
Rapport TD1 :
j'ai compilé le code avec la commande :
gcc -g -pg -o student_rank student_rank.c heapsort.c bubblesort.c
J'ai exécuté le programme avec différents nombres d'étudiants et de notes avec la commande suivante :
./student_rank <Nombre etudiants> <Nombre notes par etudiants> <mode debug (0 ou 1)>
On remarque qu'avec 1000 étudiants et 1000 notes, le temps est d'environ 3 secondes et avec 5000 étudiants et 1000 notes, nous avons environ
1 minute 25, ce qui montre que le temps d'exécution est exponentiel.
Ensuite j'ai utilisé l'outil prof pour analyser le programme :
Flat profile -> le temps et le nombre d'exécution
Call graph -> Voir l'arbre d'appel fonction + le temps et le nombre d'exécution
La fonction la plus longue est bubblesort, Nbr d'appel important
j'ai enlevé l'appel de la fonction bubblesort cela réduit le nombre d'appels et on gagne un tout petit peu de temps, mais il y a un bug
Le bug de tri vient de la fonction bubblesort car le Swapped était = 1 donc j'ai modifié le et mis swepped > 0.
Quand je remplace le bublesort par le heapsort on gagne beaucoup de temps.
Après dernière vérification avec Gprof, on remarque qu'il ne manque quasiment plus grand-chose pour optimiser car la vitesse d'exécution
est très rapide

View File

@@ -17,5 +17,5 @@ void bubblesort(int* array, int length)
swapped++;
}
}
} while(swapped==1);
} while(swapped > 0);
}

BIN
gmon.out Normal file

Binary file not shown.

BIN
student_rank Executable file

Binary file not shown.

View File

@@ -55,7 +55,7 @@ int find_rank_student(int student_grade, int* grades_array, int students_number)
{
int position = -1;
int i = 0;
bubblesort(grades_array,students_number);
for(i = students_number-1; i >= 0; i--)
{
if(grades_array[i] == student_grade)
@@ -77,7 +77,7 @@ void sort_students(int** students_rank, int** students_array, int students_numbe
{
grades[j] = students_array[j][i];
}
bubblesort(grades,students_number);
heapsort(grades,students_number);
for(j = 0; j < students_number; j++)
{
students_rank[j][i] = find_rank_student(students_array[j][i],grades,students_number);