ajout modif
This commit is contained in:
parent
ca552281c9
commit
bdc2f6e6db
23
modif/pdn.txt
Normal file
23
modif/pdn.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Gprof ./student_rank -b (-b = pour ne pas afficher tout le texte):
|
||||||
|
|
||||||
|
Flat profile :
|
||||||
|
|
||||||
|
Nous permet de voir les différentes métrique d'exec du programme comme temps(tps), nb appel, tps/fct, nom etc...
|
||||||
|
Puis nous avons un arbre d'appel du programme ou il faut regarder le numéro d'index
|
||||||
|
|
||||||
|
call graph :
|
||||||
|
|
||||||
|
les fct au dessus de la fct d'index sont les appellant (les fonctions qui appellent la fonction d'index)
|
||||||
|
ceux en dessous sont les appellé, ils sont appellé par la fonction d'index
|
||||||
|
|
||||||
|
D'ailleurs plus le nombre de note a généré est élévé, plus forcément le systeme est censé prendre du temps (métrique du temps qui augmente)
|
||||||
|
|
||||||
|
plusieurs moyen d'opti :
|
||||||
|
-réduire nombre d'appel
|
||||||
|
-modifier la fonction
|
||||||
|
-utiliser d'autre fct
|
||||||
|
|
||||||
|
On peut retirer l'un des deux appels de bubblesort, celui dans find_rank car le tableau a deja été trié préalablement dans sort_student nous faisant passer d'environ 30sec a 0.8sec
|
||||||
|
|
||||||
|
l'utilisation de heapsort fait perdre environ 0.4sec
|
||||||
|
|
125
modif/student_rank.c
Normal file
125
modif/student_rank.c
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
// Student rank
|
||||||
|
// M.Menault 2024
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "heapsort.h"
|
||||||
|
#include "bubblesort.h"
|
||||||
|
|
||||||
|
void generate_grades(int** students_array, int students_number, int grades_number)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for(i=0;i<students_number;i++)
|
||||||
|
{
|
||||||
|
students_array[i] = (int*) malloc(grades_number*sizeof(int));
|
||||||
|
generate_array(students_array[i],grades_number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void generate_ranks(int** students_array, int students_number, int grades_number)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
for(i=0;i<students_number;i++)
|
||||||
|
{
|
||||||
|
students_array[i] = (int*) malloc(grades_number*sizeof(int));
|
||||||
|
for(j=0;j<grades_number;j++)
|
||||||
|
{
|
||||||
|
students_array[i][j] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_array(int** students_array, int students_number)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for(i=0;i<students_number;i++)
|
||||||
|
{
|
||||||
|
free(students_array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_student_array(int** students_array, int students_number, int grades_number)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
printf("----------------------\n");
|
||||||
|
for(i=0;i<students_number;i++)
|
||||||
|
{
|
||||||
|
printf("Student %d : ",i);
|
||||||
|
print_array(students_array[i],grades_number);
|
||||||
|
}
|
||||||
|
printf("----------------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int find_rank_student(int student_grade, int* grades_array, int students_number)
|
||||||
|
{
|
||||||
|
int position = -1;
|
||||||
|
int i = 0;
|
||||||
|
//bubblesort(grades_array,students_number); ligne a retirer pour passer de 30sec a 0.8sec pour 1000 10000
|
||||||
|
for(i = students_number-1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if(grades_array[i] == student_grade)
|
||||||
|
{
|
||||||
|
position = students_number-i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sort_students(int** students_rank, int** students_array, int students_number, int grades_number)
|
||||||
|
{
|
||||||
|
int i = 0, j = 0;
|
||||||
|
for(i = 0; i < grades_number; i++)
|
||||||
|
{
|
||||||
|
int * grades = (int*) malloc(students_number*sizeof(int));
|
||||||
|
for(j = 0; j < students_number; j++)
|
||||||
|
{
|
||||||
|
grades[j] = students_array[j][i];
|
||||||
|
}
|
||||||
|
bubblesort(grades,students_number); // on peut changer en mettant heapsort
|
||||||
|
for(j = 0; j < students_number; j++)
|
||||||
|
{
|
||||||
|
students_rank[j][i] = find_rank_student(students_array[j][i],grades,students_number);
|
||||||
|
}
|
||||||
|
free(grades);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
int** student_grades = NULL;
|
||||||
|
int** student_ranks = NULL;
|
||||||
|
int students_length = 0;
|
||||||
|
int grades_length = 0;
|
||||||
|
int debug_mode = 0;
|
||||||
|
|
||||||
|
if(argc != 4)
|
||||||
|
{
|
||||||
|
printf("Usage : %s <number of student> <number of grade per student> <debug mode : 0|1>\n",argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
students_length = atoi(argv[1]);
|
||||||
|
grades_length = atoi(argv[2]);
|
||||||
|
debug_mode = atoi(argv[3]);
|
||||||
|
|
||||||
|
student_grades = (int**) malloc(students_length*sizeof(int*));
|
||||||
|
student_ranks = (int**) malloc(students_length*sizeof(int*));
|
||||||
|
generate_grades(student_grades,students_length,grades_length);
|
||||||
|
generate_ranks(student_ranks,students_length,grades_length);
|
||||||
|
|
||||||
|
sort_students(student_ranks,student_grades,students_length,grades_length);
|
||||||
|
|
||||||
|
if(debug_mode)
|
||||||
|
{
|
||||||
|
print_student_array(student_grades,students_length,grades_length);
|
||||||
|
print_student_array(student_ranks,students_length,grades_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
free_array(student_grades,students_length);
|
||||||
|
free_array(student_ranks,students_length);
|
||||||
|
free(student_grades);
|
||||||
|
free(student_ranks);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
BIN
student_rank
Executable file
BIN
student_rank
Executable file
Binary file not shown.
@ -77,7 +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);
|
heapsort(grades,students_number);
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user