Browse Source

etude préalable

gossa 6 years ago
parent
commit
ae8502bc80
7 changed files with 184 additions and 11 deletions
  1. 5 11
      README.md
  2. 11 0
      perf.R
  3. 41 0
      perf.dat
  4. 18 0
      perf.sh
  5. BIN
      prealable-mem.png
  6. BIN
      prealable.png
  7. 109 0
      recherche.c

+ 5 - 11
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            | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
-| Accès                | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
-|                      | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
+![plot](prealable.png)
 
 ### Consommation mémoire
 
-| Opération            | Tableau                   | Liste chaînée             |                           |
-|----------------------|---------------------------|---------------------------|---------------------------|
-| Insertion            | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
-| Accès                | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
-|                      | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
+![plot](prealable-mem.png)
 
 ### 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
 

+ 11 - 0
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()

+ 41 - 0
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

+ 18 - 0
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

BIN
prealable-mem.png


BIN
prealable.png


+ 109 - 0
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);
+}