diff --git a/Rapport TD1.txt b/Rapport TD1.txt new file mode 100644 index 0000000..9d17d25 --- /dev/null +++ b/Rapport TD1.txt @@ -0,0 +1,31 @@ +Rapport TD1 : + +J'ai compilé la commande : "gcc -g -pg -o student_rank student_rank.c heapsort.c bubblesort.c" ce qui a créé gmon.out en plus de compiler grâce +à -pg. + +Puis est lancer le code avec "./student_rank " les informations +qui seront utilisés tout le reste du TD sont 1000 étudiants, 1000 notes et mode 0. + +En ajoutant "time" devant la commande pour lancer le code l'on obtient le temps de l'exécution qui est de 3 secondes environ pour 1000 étudiants +et de plus de 1 minute pour 5000 étudiants. + +L'on utilise l'outil GPROF avec fait la commande "gprof student_rank". + +Gprof : +Flat profile = temps et nombre d'exécution par fonction +Call graph = arbre appel fonctions + temps et nombre d'exécution par fonction + +Fonction la plus lente = bubblesort + +Le problème vient du nombre d'appels de bubblesort donc il faudrait réduire son nombre d'appels. + +Dans student_rank un des appels de la fonction bubblesort est inutile, j'ai mis en commentaire l'appel de bubblesort ligne 58 de la fonction +find_rank_student dans student_rank.c. Le temps gagner est colossal. Mais un problème dans le classement car il n'est pas à 100% correct. + +L'on modifie dans bubblesort.c la ligne 20 à la place du "swapped==1" on met "swapped>0", mais du coup le code remet beaucoup de temps. + +Si l'on modifie à la ligne 80 du student_rank on change "bubblesort" par "heapsort" l'exécution est 10 fois plus rapide. +Dernière vérification avec GPROF pour voir s'il y a moyen d'optimiser plus (possiblement sift) + + +Recherche sur Wikipédia sur le Tri rapide. diff --git a/bubblesort.c b/bubblesort.c index a848827..1e88188 100644 --- a/bubblesort.c +++ b/bubblesort.c @@ -17,5 +17,5 @@ void bubblesort(int* array, int length) swapped++; } } - } while(swapped==1); + } while(swapped>0); } diff --git a/gmon.out b/gmon.out new file mode 100644 index 0000000..7bd71d2 Binary files /dev/null and b/gmon.out differ diff --git a/student_rank b/student_rank new file mode 100755 index 0000000..31da6fd Binary files /dev/null and b/student_rank differ diff --git a/student_rank.c b/student_rank.c index af84003..95fe744 100644 --- a/student_rank.c +++ b/student_rank.c @@ -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); + //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);