diff --git a/README.md b/README.md index 8e0ac0241637779827462cab3b869d6123999b0c..3080488905b350581548f26d3d89254dd534da62 100644 --- a/README.md +++ b/README.md @@ -38,23 +38,17 @@ Suite des commandes, ou script, à exécuter pour produire les données. ### Temps d'exécution -| Opération | Tableau | Liste chaînée | | -|----------------------|---------------------------|---------------------------|---------------------------| -| Insertion |  |  |  | -| Accès |  |  |  | -| |  |  |  | + ### Consommation mémoire -| Opération | Tableau | Liste chaînée | | -|----------------------|---------------------------|---------------------------|---------------------------| -| Insertion |  |  |  | -| Accès |  |  |  | -| |  |  |  | + ### Analyse des résultats préalables -Explications précises et succinctes des résultats préalables. +La mémoire se comporte exactement pareil sur les 4 versions. +Les temps d'exécutions dépendent essentiellement de l'affichage des valeurs du tableau. +La version 2 de recherche semble un peu plus rapide. ### Discussion des résultats préalables diff --git a/perf.R b/perf.R new file mode 100644 index 0000000000000000000000000000000000000000..714eae6e16e221ca99fcb6239455d08a915f96ad --- /dev/null +++ b/perf.R @@ -0,0 +1,11 @@ +#!/bin/R + +library(ggplot2) + +df <- read.table("perf.dat", header=TRUE) + +png("prealable.png") +ggplot(df,aes(x=taille,y=exectime,colour=version)) + + geom_point() + geom_smooth() + + ggtitle("Mesures préalables des 4 versions") +dev.off() diff --git a/perf.dat b/perf.dat new file mode 100644 index 0000000000000000000000000000000000000000..c4659563aac497669c47d928c7019e775ac47a4f --- /dev/null +++ b/perf.dat @@ -0,0 +1,41 @@ +test taille version exectime mem +1 21800000 v4 0.45 86668 +1 21800000 v2 0.56 86676 +1 21800000 v1 2.30 86768 +1 21800000 v3 2.14 86768 +2 14057000 v4 0.31 56508 +2 14057000 v2 0.36 56432 +2 14057000 v3 1.45 56452 +2 14057000 v1 1.54 56420 +3 5089000 v4 0.10 21484 +3 5089000 v2 0.13 21476 +3 5089000 v3 0.52 21388 +3 5089000 v1 0.53 21460 +4 9411000 v4 0.20 38300 +4 9411000 v2 0.22 38304 +4 9411000 v3 0.94 38372 +4 9411000 v1 0.98 38272 +5 32386000 v4 0.71 128116 +5 32386000 v2 0.80 128116 +5 32386000 v3 3.28 128040 +5 32386000 v1 3.46 128088 +6 15352000 v4 0.34 61484 +6 15352000 v2 0.39 61516 +6 15352000 v3 1.62 61480 +6 15352000 v1 1.64 61504 +7 17015000 v4 0.37 68004 +7 17015000 v2 0.42 68008 +7 17015000 v3 1.72 67988 +7 17015000 v1 1.79 68012 +8 14627000 v4 0.31 58720 +8 14627000 v2 0.37 58804 +8 14627000 v3 1.57 58748 +8 14627000 v1 1.62 58660 +9 23156000 v4 0.49 91976 +9 23156000 v2 0.59 92036 +9 23156000 v3 2.44 92064 +9 23156000 v1 2.45 92064 +10 31361000 v2 0.77 124112 +10 31361000 v4 0.68 124112 +10 31361000 v3 3.19 124052 +10 31361000 v1 3.32 124036 diff --git a/perf.sh b/perf.sh new file mode 100755 index 0000000000000000000000000000000000000000..6c44231d3e745e06f095f148e600bc27b13d4ede --- /dev/null +++ b/perf.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +echo -e "test\ttaille\tversion\texectime\tmem" + +for test in `seq 1 10` +do + taille=${RANDOM}000 + + for version in 1 2 3 4 + do + ( + res=`(/usr/bin/time -f "%U\t%M" ./recherche $taille $version > /dev/null) 2>&1` + + echo -e "$test\t$taille\tv$version\t$res" + ) & + done + wait +done diff --git a/prealable-mem.png b/prealable-mem.png new file mode 100644 index 0000000000000000000000000000000000000000..ed615c1d8727cf95a1f3f5fc51cd5d480aad59d1 Binary files /dev/null and b/prealable-mem.png differ diff --git a/prealable.png b/prealable.png new file mode 100644 index 0000000000000000000000000000000000000000..3ec4b707d4adc9f817728d0c0b3578b72cac4009 Binary files /dev/null and b/prealable.png differ diff --git a/recherche.c b/recherche.c new file mode 100644 index 0000000000000000000000000000000000000000..9e22c1ea5252eab6bd62ae3c464236f716e84815 --- /dev/null +++ b/recherche.c @@ -0,0 +1,109 @@ +/** + Recherche d'un entier alétoire dans un tableau de valeurs aléatoires + */ + +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define MAX_VALEUR 150000 + +int *generer_tableau(long long unsigned int n) +{ + int *tableau = malloc(n*sizeof(int)); + long long unsigned int i; + + for (i=0; i<n; i++) { + tableau[i] = rand()%MAX_VALEUR; + } + + return tableau; +} + +void afficher_tableau(int *tableau, long long unsigned int n) +{ + long long unsigned int i; + for (i=0; i<n; i++) { + printf("%d ",tableau[i]); + } + printf("\n"); + +} + +char rechercherV1(int *tableau, long long unsigned int n, int valeur) +{ + long long unsigned int i; + char trouve = 0; + + for (i=0; i<n; i++) { + if (tableau[i] == valeur) { + trouve=1; + } + } + + return trouve; +} + +char rechercherV2(int *tableau, long long unsigned int n, int valeur) +{ + long long unsigned int i; + char trouve = 0; + + for (i=0; i<n; i++) { + if (tableau[i] == valeur) { + return 1; + } + } + + return 0; +} + + +int main(int argc, char *argv[]) +{ + int *tableau; + int taille, valeur; + char trouve; + int version; + + if (argc<2) { + printf("%s: opérande manquant\n",argv[0]); + printf("Recherche une valeur aléatoire dans un tableau d'entier aléatoire de taille n\n"); + printf("Affiche le tableau et renvoie 1 si la valeur est trouvée, 0 sinon\n"); + exit(1); + printf("Usage: %s taille version [graine]\n",argv[0]); + } + + unsigned int graine; + if (argc>3) { + graine = atoi(argv[3]); + } else { + graine = time(NULL); + } + + srand(graine); + + taille = strtoull(argv[1], (char **) NULL, 10); + version = strtoull(argv[2], (char **) NULL, 10); + valeur = rand()%MAX_VALEUR; + tableau = generer_tableau(taille); + + switch(version) { + case 1: + afficher_tableau(tableau,taille); + trouve = rechercherV1(tableau, taille, valeur); + break; + case 2: + trouve = rechercherV1(tableau, taille, valeur); + break; + case 3: + afficher_tableau(tableau,taille); + trouve = rechercherV2(tableau, taille, valeur); + break; + case 4: + trouve = rechercherV2(tableau, taille, valeur); + break; + } + + printf("Valeur %d trouve: %d\n",valeur, trouve); +}