controle
This commit is contained in:
53
controle.pdf
Normal file
53
controle.pdf
Normal file
@@ -0,0 +1,53 @@
|
||||
Contrôle Machine
|
||||
DEV5.1 Qualité algorithmique
|
||||
|
||||
|
||||
Exo 2 :
|
||||
|
||||
Profiler :
|
||||
Je n'ai pas eu de résultat de profiler, j'ai bien exécuter ces commandes :
|
||||
gcc -pg main.c -o app
|
||||
./app
|
||||
gprof "app.exe" gmon.out
|
||||
|
||||
Mais mon terminal me renvoyait : granularity: each sample hit covers 4 byte(s) no time propagated
|
||||
J'ai donc fait des recherches, il était dit que c'était possiblement que le code s'éxécutais trop rapidement, j'ai donc fait répréter la fonction plusieurs fois pour que ça dure au moins quelques secondes, mais j'ai obtennu le même résultat.
|
||||
J'ai ensuite lu que sur windows le profiler pouvait bugger
|
||||
|
||||
Calculer la complexité cyclomatique de racineCarree() et racineCarreeTab() :
|
||||
Si j'ai bien compris le calcul de complexité cyclomatique reviens a calculer le nombre maximum de chemins d'exécutions possible
|
||||
|
||||
Sur racineCarree(), j'en compte 6, 2 au début pour la vérification de 0 ou 1, 1 pour le while, 1 pour la condition dans le while et les deux dernières à la fin de la fonction, le if et else.
|
||||
Il faut donc 6 tests pour couvrir l'entièreté de la fonction racineCarree()
|
||||
|
||||
Sur racineCarreTab(), j'en compte 2, une pour l'éxecution du for si tab n'est pas vide et 1 si elle est vide
|
||||
Il faut donc 2 tests pour couvrir l'entièreté de la fonction racineCarreeTab()
|
||||
|
||||
|
||||
Calculer la complexité algorithmique de racineCarree() et racineCarreeTab() :
|
||||
|
||||
Sur racineCarree(), O(n), le résultat dépend directement de la valeur nb
|
||||
Sur racineCarreeTab(), O(M * n), le résultat dépend de n dans execution de taille pour tab
|
||||
|
||||
|
||||
Exo 4 :
|
||||
Profiler :
|
||||
Pareil que pour l'exo 2
|
||||
|
||||
|
||||
Calculer la complexité cyclomatique de TriSpecial() :
|
||||
Ici j'en compte 12, 2 au début, pour le for et le if qui compte le nombre de non entier, 1 if pour vérifier si le nombre de non entier est pair, 1 for pour le calcul de la somme dans ce if, et 3 pour le for et if pour gérer si c'est pair ou impair
|
||||
Donc 7 pour cette première partie
|
||||
Puis 1 de base comme on rentre dans le else, 1 pour le for qui calcul la somme et 3 pour le for et if qui regarde si c'est pair ou non.
|
||||
|
||||
|
||||
Calculer la complexité algorithmique de TriSpecial() :
|
||||
O(M * n), le résultat dépend de n dans execution de taille pour tab
|
||||
|
||||
|
||||
Pour les exo 2 et 4 j'ai fais du mieux que j'ai pu, je n'ai pas suivi les cours en début d'année puisque je suis arrivée début octobre
|
||||
J'ai également perdu pas mal de temps a essayer de régler le problème avec le profiler
|
||||
|
||||
Pour tester :
|
||||
gcc -pg main.c -o app
|
||||
./app
|
142
gp-result.txt
Normal file
142
gp-result.txt
Normal file
@@ -0,0 +1,142 @@
|
||||
Pourtant ça a bien durer quelques secondes:
|
||||
|
||||
G:/Mon Drive/Ecole/BUT/DEV 5.1/CONTROLE_DEV51_Creuzet $ gprof ./app.exe gmon.out
|
||||
Flat profile:
|
||||
|
||||
Each sample counts as 0.01 seconds.
|
||||
% cumulative self self total
|
||||
time seconds seconds calls Ts/call Ts/call name
|
||||
|
||||
% the percentage of the total running time of the
|
||||
time program used by this function.
|
||||
|
||||
cumulative a running sum of the number of seconds accounted
|
||||
seconds for by this function and those listed above it.
|
||||
|
||||
self the number of seconds accounted for by this
|
||||
seconds function alone. This is the major sort for this
|
||||
listing.
|
||||
|
||||
calls the number of times this function was invoked, if
|
||||
this function is profiled, else blank.
|
||||
|
||||
self the average number of milliseconds spent in this
|
||||
ms/call function per call, if this function is profiled,
|
||||
else blank.
|
||||
|
||||
total the average number of milliseconds spent in this
|
||||
ms/call function and its descendents per call, if this
|
||||
function is profiled, else blank.
|
||||
|
||||
name the name of the function. This is the minor sort
|
||||
for this listing. The index shows the location of
|
||||
the function in the gprof listing. If the index is
|
||||
in parenthesis it shows where it would appear in
|
||||
the gprof listing if it were to be printed.
|
||||
|
||||
|
||||
Copyright (C) 2012-2025 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
|
||||
Call graph (explanation follows)
|
||||
|
||||
|
||||
granularity: each sample hit covers 4 byte(s) no time propagated
|
||||
|
||||
index % time self children called name
|
||||
|
||||
This table describes the call tree of the program, and was sorted by
|
||||
the total amount of time spent in each function and its children.
|
||||
|
||||
Each entry in this table consists of several lines. The line with the
|
||||
index number at the left hand margin lists the current function.
|
||||
The lines above it list the functions that called this function,
|
||||
and the lines below it list the functions this one called.
|
||||
This line lists:
|
||||
index A unique number given to each element of the table.
|
||||
Index numbers are sorted numerically.
|
||||
The index number is printed next to every function name so
|
||||
it is easier to look up where the function is in the table.
|
||||
|
||||
% time This is the percentage of the `total' time that was spent
|
||||
in this function and its children. Note that due to
|
||||
different viewpoints, functions excluded by options, etc,
|
||||
these numbers will NOT add up to 100%.
|
||||
|
||||
self This is the total amount of time spent in this function.
|
||||
|
||||
children This is the total amount of time propagated into this
|
||||
function by its children.
|
||||
|
||||
called This is the number of times the function was called.
|
||||
If the function called itself recursively, the number
|
||||
only includes non-recursive calls, and is followed by
|
||||
a `+' and the number of recursive calls.
|
||||
|
||||
name The name of the current function. The index number is
|
||||
printed after it. If the function is a member of a
|
||||
cycle, the cycle number is printed between the
|
||||
function's name and the index number.
|
||||
|
||||
|
||||
For the function's parents, the fields have the following meanings:
|
||||
|
||||
self This is the amount of time that was propagated directly
|
||||
from the function into this parent.
|
||||
|
||||
children This is the amount of time that was propagated from
|
||||
the function's children into this parent.
|
||||
|
||||
called This is the number of times this parent called the
|
||||
function `/' the total number of times the function
|
||||
was called. Recursive calls to the function are not
|
||||
included in the number after the `/'.
|
||||
|
||||
name This is the name of the parent. The parent's index
|
||||
number is printed after it. If the parent is a
|
||||
member of a cycle, the cycle number is printed between
|
||||
the name and the index number.
|
||||
|
||||
If the parents of the function cannot be determined, the word
|
||||
`<spontaneous>' is printed in the `name' field, and all the other
|
||||
fields are blank.
|
||||
|
||||
For the function's children, the fields have the following meanings:
|
||||
|
||||
self This is the amount of time that was propagated directly
|
||||
from the child into the function.
|
||||
|
||||
children This is the amount of time that was propagated from the
|
||||
child's children to the function.
|
||||
|
||||
called This is the number of times the function called
|
||||
this child `/' the total number of times the child
|
||||
was called. Recursive calls by the child are not
|
||||
listed in the number after the `/'.
|
||||
|
||||
name This is the name of the child. The child's index
|
||||
number is printed after it. If the child is a
|
||||
member of a cycle, the cycle number is printed
|
||||
between the name and the index number.
|
||||
|
||||
If there are any cycles (circles) in the call graph, there is an
|
||||
entry for the cycle-as-a-whole. This entry shows who called the
|
||||
cycle (as parents) and the members of the cycle (as children.)
|
||||
The `+' recursive calls entry shows the number of function calls that
|
||||
were internal to the cycle, and the calls entry for each member shows,
|
||||
for that member, how many times it was called from other members of
|
||||
the cycle.
|
||||
|
||||
|
||||
Copyright (C) 2012-2025 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
|
||||
Index by function name
|
192
main.c
Normal file
192
main.c
Normal file
@@ -0,0 +1,192 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Renvoie la racine carrée d'un nombre entier positif, sinon -1
|
||||
int racineCarre(int nb) {
|
||||
if (nb == 0 || nb == 1) return nb;
|
||||
|
||||
int prob = nb / 2;
|
||||
int nextProb;
|
||||
|
||||
while (1) {
|
||||
nextProb = (prob + nb / prob) / 2;
|
||||
|
||||
if (nextProb >= prob) {
|
||||
break;
|
||||
};
|
||||
|
||||
prob = nextProb;
|
||||
}
|
||||
|
||||
if ((prob * prob) == nb) {
|
||||
return prob;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Renvoie un tableau de racine carré de tab
|
||||
int* racineCarreTab(int tab[], int taille) {
|
||||
int* result = (int*)malloc(taille * sizeof(int));
|
||||
for (int i = 0; i < taille; i++) {
|
||||
result[i] = racineCarre(tab[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Renvoie un tableau tirer
|
||||
int* TriSpecial(int tab[], int taille) {
|
||||
int nonEntier = 0;
|
||||
for (int i = 0; i < taille; i++) {
|
||||
if (racineCarre(tab[i]) == -1) {
|
||||
nonEntier++;
|
||||
}
|
||||
}
|
||||
|
||||
int* result = (int*)malloc(taille * sizeof(int));
|
||||
|
||||
if (nonEntier % 2 == 0) {
|
||||
int somme = 0;
|
||||
for (int i = 0; i < taille; i++) {
|
||||
somme += tab[i]; // Calcul somme
|
||||
}
|
||||
|
||||
for (int i = 0; i < taille; i++) {
|
||||
if (i % 2 == 0) { // Pair
|
||||
result[i] = tab[i];
|
||||
} else { // Impair
|
||||
result[i] = somme * tab[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int* racines = (int*)malloc(taille * sizeof(int));
|
||||
int somme = 0;
|
||||
for (int i = 0; i < taille; i++) {
|
||||
racines[i] = racineCarre(tab[i]);
|
||||
somme += racines[i]; // Calcul somme
|
||||
}
|
||||
|
||||
for (int i = 0; i < taille; i++) {
|
||||
if (i % 2 == 0) { // Pair
|
||||
result[i] = racines[i];
|
||||
} else { // Impair
|
||||
result[i] = somme * tab[i];
|
||||
}
|
||||
}
|
||||
|
||||
free(racines);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("========== Test racineCarre ==========\n");
|
||||
printf("racineCarre(9) = %d\n", racineCarre(9));
|
||||
printf("racineCarre(10) = %d\n", racineCarre(10));
|
||||
printf("\n");
|
||||
|
||||
printf("========== Test racineCarreTab ==========\n");
|
||||
int tab1[] = {9, 25, 4};
|
||||
int tab2[] = {10, 36, 2};
|
||||
|
||||
int* result1 = racineCarreTab(tab1, 3);
|
||||
printf("racineCarreTab([9, 25, 4]) = ");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
printf("%d ", result1[i]);
|
||||
}
|
||||
printf("\n");
|
||||
free(result1);
|
||||
|
||||
int* result2 = racineCarreTab(tab2, 3);
|
||||
printf("racineCarreTab([10, 36, 2]) = ");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
printf("%d ", result2[i]);
|
||||
}
|
||||
printf("\n\n");
|
||||
free(result2);
|
||||
|
||||
printf("========== Test TriSpecial ==========\n");
|
||||
int tab3[] = {3, 5, 25, 16};
|
||||
int* result3 = TriSpecial(tab3, 4);
|
||||
printf("TriSpecial([3, 5, 25, 16]) = ");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("%d ", result3[i]);
|
||||
}
|
||||
printf("\n");
|
||||
free(result3);
|
||||
|
||||
int tab4[] = {36, 9, 100, 2, 3, 7};
|
||||
int* result4 = TriSpecial(tab4, 6);
|
||||
printf("TriSpecial([36, 9, 100, 2, 3, 7]) = ");
|
||||
for (int i = 0; i < 6; i++) {
|
||||
printf("%d ", result4[i]);
|
||||
}
|
||||
printf("\n\n");
|
||||
free(result4);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// int main(void) {
|
||||
// Racine carrée
|
||||
// printf("%d\n", racineCarre(9));
|
||||
// printf("%d\n", racineCarre(16));
|
||||
// printf("-----------------\n");
|
||||
// donne bien racineCarree(9) → 3 et racineCarree(10) → -1
|
||||
|
||||
// Racine carrée tab
|
||||
// int tab1[] = {9,25,4};
|
||||
// int tab2[] = {10,36,2};
|
||||
// int* result1 = racineCarreTab(tab1, 3);
|
||||
// int* result2 = racineCarreTab(tab2, 3);
|
||||
// for (int i = 0; i < 3; i++) {
|
||||
// printf("%d ", result1[i]);
|
||||
// }
|
||||
|
||||
// for (int i = 0; i < 3; i++) {
|
||||
// printf("%d ", result2[i]);
|
||||
// }
|
||||
|
||||
// Test profiler avec racineCarrreTab
|
||||
// int tab[10000];
|
||||
// for (int i = 0; i < 10000; i++) {
|
||||
// tab[i] = 1000000 + i;
|
||||
// }
|
||||
|
||||
// for (int repeat = 0; repeat < 10000; repeat++) {
|
||||
// int* a = racineCarreTab(tab, 10000);
|
||||
// free(a);
|
||||
// }
|
||||
|
||||
// Tri spéciale
|
||||
// int tab1[] = {3, 5, 25, 16};
|
||||
// int* result1 = TriSpecial(tab1, 4);
|
||||
// printf("Test 1 : ");
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
// printf("%d ", result1[i]);
|
||||
// }
|
||||
// printf("\n");
|
||||
// free(result1);
|
||||
// // donne bien TriSpecial([3,5,25,16]) → [3,245,25,784]
|
||||
|
||||
// int tab2[] = {36, 9, 100, 2, 3, 7};
|
||||
// int* result2 = TriSpecial(tab2, 6);
|
||||
// printf("Test 2 : ");
|
||||
// for (int i = 0; i < 6; i++) {
|
||||
// printf("%d ", result2[i]);
|
||||
// }
|
||||
// printf("\n");
|
||||
// free(result2);
|
||||
// donne bien TriSpecial([36,9,100,2,3,7]) → [6,144,10,32,-1,112]
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// gcc main.c -o app
|
||||
// ./app
|
||||
|
||||
// (Profiling)
|
||||
// gcc -pg main.c -o app
|
||||
// ./app
|
||||
// gprof "app.exe" gmon.out
|
Reference in New Issue
Block a user