Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
80b52fdf28 | |||
2e88e78c75 | |||
e79d0ca56f | |||
71b9841e88 |
55
Résultat.txt
Normal file
55
Résultat.txt
Normal file
@@ -0,0 +1,55 @@
|
||||
J'ai essayé avec 100000 étudiant et 10000 notes sans debug, ça prend beacoup de temps
|
||||
Ensuite avec 1000 étudiant et 1000 notes, ça prend environ 3 secondes.
|
||||
Puis avec 5 fois plus d'étudiant, ça prend 1 minutes et 18 secondes.
|
||||
|
||||
Avec 1000 étudiants et 1000 notes sans debug on utilise gprof pour le profiling.
|
||||
On peut voir que les fonctions qui prennent le plus de temps sont find_rank_student et bubblesort avec bubblesort qui prend 81.43 % du temps d'exécution.
|
||||
|
||||
% cumulative self self total
|
||||
time seconds seconds calls s/call s/call name
|
||||
81.43 2.39 2.39 1001000 0.00 0.00 bubblesort
|
||||
18.40 2.93 0.54 1000000 0.00 0.00 find_rank_student
|
||||
0.34 2.94 0.01 1 0.01 2.94 sort_students
|
||||
0.00 2.94 0.00 1000 0.00 0.00 generate_array
|
||||
0.00 2.94 0.00 2 0.00 0.00 free_array
|
||||
0.00 2.94 0.00 1 0.00 0.00 generate_grades
|
||||
0.00 2.94 0.00 1 0.00 0.00 generate_ranks
|
||||
|
||||
index % time self children called name
|
||||
0.01 2.93 1/1 main [2]
|
||||
[1] 100.0 0.01 2.93 1 sort_students [1]
|
||||
0.54 2.39 1000000/1000000 find_rank_student [3]
|
||||
0.00 0.00 1000/1001000 bubblesort [4]
|
||||
-----------------------------------------------
|
||||
<spontaneous>
|
||||
[2] 100.0 0.00 2.94 main [2]
|
||||
0.01 2.93 1/1 sort_students [1]
|
||||
0.00 0.00 2/2 free_array [6]
|
||||
0.00 0.00 1/1 generate_grades [7]
|
||||
0.00 0.00 1/1 generate_ranks [8]
|
||||
-----------------------------------------------
|
||||
0.54 2.39 1000000/1000000 sort_students [1]
|
||||
[3] 99.6 0.54 2.39 1000000 find_rank_student [3]
|
||||
2.39 0.00 1000000/1001000 bubblesort [4]
|
||||
-----------------------------------------------
|
||||
0.00 0.00 1000/1001000 sort_students [1]
|
||||
2.39 0.00 1000000/1001000 find_rank_student [3]
|
||||
[4] 81.3 2.39 0.00 1001000 bubblesort [4]
|
||||
-----------------------------------------------
|
||||
0.00 0.00 1000/1000 generate_grades [7]
|
||||
[5] 0.0 0.00 0.00 1000 generate_array [5]
|
||||
-----------------------------------------------
|
||||
0.00 0.00 2/2 main [2]
|
||||
[6] 0.0 0.00 0.00 2 free_array [6]
|
||||
-----------------------------------------------
|
||||
0.00 0.00 1/1 main [2]
|
||||
[7] 0.0 0.00 0.00 1 generate_grades [7]
|
||||
0.00 0.00 1000/1000 generate_array [5]
|
||||
-----------------------------------------------
|
||||
0.00 0.00 1/1 main [2]
|
||||
[8] 0.0 0.00 0.00 1 generate_ranks [8]
|
||||
-----------------------------------------------
|
||||
|
||||
On modifie d'abord bubblesort pour qu'il fonctionne correctement en remplaçant swapped ++ par swapped = 1.
|
||||
Ensuite on supprime le bubblesort qui est dans la fonction find_rank_student pour gagner du temps sauf qu'on ne gagne pas assez de temps pour passer en dessous d'une secondes.
|
||||
Quand on remplace le bubblesort restant par heapsort, c'est beacoup plus rapide sauf que le tri ne ce fait pas bien.
|
@@ -14,7 +14,7 @@ void bubblesort(int* array, int length)
|
||||
tmp = array[i-1];
|
||||
array[i-1] = array[i];
|
||||
array[i] = tmp;
|
||||
swapped++;
|
||||
swapped= 1;
|
||||
}
|
||||
}
|
||||
} while(swapped==1);
|
||||
|
32
quicksort.c
Normal file
32
quicksort.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// Fonction pour échanger deux entiers
|
||||
void swap(int *a, int *b) {
|
||||
int temp = *a;
|
||||
*a = *b;
|
||||
*b = temp;
|
||||
}
|
||||
|
||||
// Partition du tableau
|
||||
int partition(int arr[], int low, int high) {
|
||||
int pivot = arr[high]; // Choisir le dernier élément comme pivot
|
||||
int i = low - 1;
|
||||
|
||||
for (int j = low; j < high; j++) {
|
||||
if (arr[j] <= pivot) {
|
||||
i++;
|
||||
swap(&arr[i], &arr[j]);
|
||||
}
|
||||
}
|
||||
swap(&arr[i + 1], &arr[high]);
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
// Fonction récursive QuickSort
|
||||
void quicksort(int arr[], int low, int high) {
|
||||
if (low < high) {
|
||||
int pi = partition(arr, low, high);
|
||||
quicksort(arr, low, pi - 1);
|
||||
quicksort(arr, pi + 1, high);
|
||||
}
|
||||
}
|
8
quicksort.h
Normal file
8
quicksort.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __QUICKSORT__
|
||||
#define __QUICKSORT__
|
||||
|
||||
void swap(int *a, int *b);
|
||||
int partition(int arr[], int low, int high);
|
||||
void quickshort(int arr[], int low, int high);
|
||||
|
||||
#endif
|
BIN
student_rank
Executable file
BIN
student_rank
Executable file
Binary file not shown.
@@ -5,6 +5,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "heapsort.h"
|
||||
#include "bubblesort.h"
|
||||
#include "quicksort.h"
|
||||
|
||||
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 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);
|
||||
|
Reference in New Issue
Block a user