This commit is contained in:
2025-09-10 17:21:59 +02:00
parent ca552281c9
commit 83c915801c
7 changed files with 237 additions and 4 deletions

200
TD1.txt Normal file
View File

@@ -0,0 +1,200 @@
DAVID AKAGUNDUZ ET JAMES BOUTARIC
TD1
Nous avons commencé par lancer les progmramme récuprér depuis le git de Maxime Menault puis nous les avons compiler et lancer avec des valeur qui prenne un peu de temps nous avons decider de prendre comem valeur 1000 et 1000 pour que ca dure un minimun de temps d'éxécution
ex : gcc -g -pg -o student_rank student_rank.c heapsort.c bubblesort.c
./student_rank 5000 1000 0
Suite a cela nous utilisons gprof pour analyser le programme lancer ,
gprof ./student_rank
il y a plussieur information qu'on peut retrouver comme :
le temps de répartition entre les differentes fonctions,
le temps d'd'éxecution cumulé au fur et à mesure (dans l'ordre d'utilisation des fonction) ,
le temps pris par chacune des fonctions,
le nombre de fois que la fonction a était appeller,
le nombre de temps pris par appel en milliseconde,
le nombre total pris pour avoir éxécuter tout les appel de la fonction et aussi celle que lui appel (ses enfants).
enfin le nom de la fonction en question.
ex:
Flat Profile
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
79.80 2.35 2.35 1001000 0.00 0.00 bubblesort
19.35 2.92 0.57 1000000 0.00 0.00 find_rank_student
0.34 2.93 0.01 1000 0.00 0.00 generate_array
0.34 2.94 0.01 1 0.01 0.01 generate_ranks
0.34 2.96 0.01 1 0.01 2.93 sort_students
0.00 2.96 0.00 2 0.00 0.00 free_array
0.00 2.96 0.00 1 0.00 0.01 generate_grades
----------------------------------------------------------------------------------------------
Call graph (explanation follows)
granularity: each sample hit covers 2 byte(s) for 0.34% of 2.96 seconds
index % time self children called name
<spontaneous>
[1] 100.0 0.00 2.96 main [1]
0.01 2.92 1/1 sort_students [2]
0.00 0.01 1/1 generate_grades [6]
0.01 0.00 1/1 generate_ranks [7]
0.00 0.00 2/2 free_array [8]
-----------------------------------------------
0.01 2.92 1/1 main [1]
[2] 99.3 0.01 2.92 1 sort_students [2]
0.57 2.35 1000000/1000000 find_rank_student [3]
0.00 0.00 1000/1001000 bubblesort [4]
-----------------------------------------------
0.57 2.35 1000000/1000000 sort_students [2]
[3] 98.9 0.57 2.35 1000000 find_rank_student [3]
2.35 0.00 1000000/1001000 bubblesort [4]
-----------------------------------------------
0.00 0.00 1000/1001000 sort_students [2]
2.35 0.00 1000000/1001000 find_rank_student [3]
[4] 79.7 2.35 0.00 1001000 bubblesort [4]
-----------------------------------------------
0.01 0.00 1000/1000 generate_grades [6]
[5] 0.3 0.01 0.00 1000 generate_array [5]
-----------------------------------------------
0.00 0.01 1/1 main [1]
[6] 0.3 0.00 0.01 1 generate_grades [6]
0.01 0.00 1000/1000 generate_array [5]
-----------------------------------------------
0.01 0.00 1/1 main [1]
[7] 0.3 0.01 0.00 1 generate_ranks [7]
-----------------------------------------------
0.00 0.00 2/2 main [1]
[8] 0.0 0.00 0.00 2 free_array [8]
-----------------------------------------------
les information comme :
l'index (pour chaque element de la table)
le pourcentage detemsp pris par chacune des des fonction et de ses enfants
Self le nomre total de temps pris par la fonction
Children le nombre total pris par ses enfant
Le nombre de fois que la fonction est appeler
ainsi quele nom de la fonction en question
Résumer :
Le grpof :
----> Flat profile : temps et nbr d'éxecution/fonctions (ici bublesort 80%)
----> Call Graph : Vor arbre fonction + temps et nombre d'éxecution/fonction
Fonction la plus lente: bubblesort
Nombre appel important de bubblesort dans le find_rank_student
Nous avons analyser le code et nosu avons trouvé comment optimiser en reduisant le temps d'éxecution dans le code ( i lfaut supprimer l'apple dela fonction bubblesort dans find_rank_student)
Pour corriger l'erreur du calssement des note des élève il faut modiifer la condition du tri a bulle ( bubblesort) car sa condition n'était correct du fait qu'elle valide en permanance sa condition.( mauvaise condition i ldoit verifier qu'il y a aucun échange entre pour que ca soit bon)
void bubblesort(int* array, int length)
{
int swapped, i, tmp;
do
{
swapped = 0;
for(i=1;i<length;i++)
{
if(array[i-1] > array[i])
{
tmp = array[i-1];
array[i-1] = array[i];
array[i] = tmp;
swapped++;
}
}
} while(swapped>0);
}
----------------------------------------------
Si on change bubblesort par heapsort alors le temps d'exécution est beaucoup plus rapide
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
100.17 0.04 0.04 1000000 0.00 0.00 find_rank_student
0.00 0.04 0.00 1500000 0.00 0.00 sift
0.00 0.04 0.00 1000 0.00 0.00 generate_array
0.00 0.04 0.00 1000 0.00 0.00 heapsort
0.00 0.04 0.00 2 0.00 0.00 free_array
0.00 0.04 0.00 1 0.00 0.00 generate_grades
0.00 0.04 0.00 1 0.00 0.00 generate_ranks
0.00 0.04 0.00 1 0.00 40.07 sort_students
--------------------------------------------------
Call graph
granularity: each sample hit covers 2 byte(s) for 24.96% of 0.04 seconds
index % time self children called name
0.04 0.00 1000000/1000000 sort_students [2]
[1] 100.0 0.04 0.00 1000000 find_rank_student [1]
-----------------------------------------------
0.00 0.04 1/1 main [3]
[2] 100.0 0.00 0.04 1 sort_students [2]
0.04 0.00 1000000/1000000 find_rank_student [1]
0.00 0.00 1000/1000 heapsort [6]
-----------------------------------------------
<spontaneous>
[3] 100.0 0.00 0.04 main [3]
0.00 0.04 1/1 sort_students [2]
0.00 0.00 2/2 free_array [7]
0.00 0.00 1/1 generate_grades [8]
0.00 0.00 1/1 generate_ranks [9]
-----------------------------------------------
384971 sift [4]
0.00 0.00 1500000/1500000 heapsort [6]
[4] 0.0 0.00 0.00 1500000+384971 sift [4]
384971 sift [4]
-----------------------------------------------
0.00 0.00 1000/1000 generate_grades [8]
[5] 0.0 0.00 0.00 1000 generate_array [5]
-----------------------------------------------
0.00 0.00 1000/1000 sort_students [2]
[6] 0.0 0.00 0.00 1000 heapsort [6]
0.00 0.00 1500000/1500000 sift [4]
-----------------------------------------------
0.00 0.00 2/2 main [3]
[7] 0.0 0.00 0.00 2 free_array [7]
-----------------------------------------------
0.00 0.00 1/1 main [3]
[8] 0.0 0.00 0.00 1 generate_grades [8]
0.00 0.00 1000/1000 generate_array [5]
-----------------------------------------------
0.00 0.00 1/1 main [3]
[9] 0.0 0.00 0.00 1 generate_ranks [9]
-----------------------------------------------

View File

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

BIN
gmon.out Normal file

Binary file not shown.

28
quicksort.c Normal file
View File

@@ -0,0 +1,28 @@
#include "quicksort.h"
int partition(int* array, int low, int high)
{
int pivot = array[high];
int i = low -1;
int j =low;
for (j;j<high;j++){
if (array[j]<= pivot){
i=i+1;
int a=array[j];
array[j]=array[i];
array[i]=a;
}
}
int b = array[i+1];
array[i+1]=array[high];
array[high]=b;
return i+1;
}
void quicksort(int* array,int low, int high){
if (low<high){
int pi=partition(array,low,high);
quicksort(array,low,pi-1);
quicksort(array,pi+1,high);
}
}

6
quicksort.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef QUICKSORT_H
#define QUICKSORT_H
void quicksort(int* array, int low, int high);
#endif

BIN
student_rank Executable file

Binary file not shown.

View File

@@ -5,6 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "heapsort.h" #include "heapsort.h"
#include "bubblesort.h" #include "bubblesort.h"
#include "quicksort.h"
void generate_grades(int** students_array, int students_number, int grades_number) void generate_grades(int** students_array, int students_number, int grades_number)
{ {
@@ -55,7 +56,6 @@ int find_rank_student(int student_grade, int* grades_array, int students_number)
{ {
int position = -1; int position = -1;
int i = 0; int i = 0;
bubblesort(grades_array,students_number);
for(i = students_number-1; i >= 0; i--) for(i = students_number-1; i >= 0; i--)
{ {
if(grades_array[i] == student_grade) if(grades_array[i] == student_grade)
@@ -77,8 +77,7 @@ void sort_students(int** students_rank, int** students_array, int students_numbe
{ {
grades[j] = students_array[j][i]; grades[j] = students_array[j][i];
} }
bubblesort(grades,students_number); quicksort(grades, 0, students_number - 1); for(j = 0; j < students_number; j++)
for(j = 0; j < students_number; j++)
{ {
students_rank[j][i] = find_rank_student(students_array[j][i],grades,students_number); students_rank[j][i] = find_rank_student(students_array[j][i],grades,students_number);
} }