Benchmark
 All Classes Files Functions Variables Typedefs Macros
Classes | Macros | Functions
argfct.c File Reference

Ce programme compare le temps nécessaire pour passer un argument de N byte à une fonction et celui nécessaire pour passer le pointeur vers cet argument. More...

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
#include "benchmark.h"

Classes

struct  arg1
 
struct  arg2
 
struct  arg4
 
struct  arg8
 
struct  arg16
 
struct  arg32
 
struct  arg64
 
struct  arg128
 

Macros

#define MAX_SIZE   3
 
#define TURN   100000000
 

Functions

void fctpt (void *arg)
 
void fctval1 (struct arg1 arg)
 
void fctval2 (struct arg2 arg)
 
void fctval4 (struct arg4 arg)
 
void fctval8 (struct arg8 arg)
 
void fctval16 (struct arg16 arg)
 
void fctval32 (struct arg32 arg)
 
void fctval64 (struct arg64 arg)
 
void fctval128 (struct arg128 arg)
 
int main (int argc, char *argv[])
 

Detailed Description

Ce programme compare le temps nécessaire pour passer un argument de N byte à une fonction et celui nécessaire pour passer le pointeur vers cet argument.

Compare donc les performances en passant des arguments de plus en plus gros sur le stack contre un pointeur de taille fixe

Note : Pour ne pas polluer les tests, il a été décidé de ne pas utiliser de pointeurs de fonction.

Macro Definition Documentation

#define MAX_SIZE   3
#define TURN   100000000

Function Documentation

void fctpt ( void *  arg)
40 {}
void fctval1 ( struct arg1  arg)
42 {}
void fctval128 ( struct arg128  arg)
49 {}
void fctval16 ( struct arg16  arg)
46 {}
void fctval2 ( struct arg2  arg)
43 {}
void fctval32 ( struct arg32  arg)
47 {}
void fctval4 ( struct arg4  arg)
44 {}
void fctval64 ( struct arg64  arg)
48 {}
void fctval8 ( struct arg8  arg)
45 {}
int main ( int  argc,
char *  argv[] 
)
52  {
53  timer *t = timer_alloc();
54  recorder *val_rec = recorder_alloc("argfct-val.csv");
55  recorder *pt_rec = recorder_alloc("argfct-pt.csv");
56 
57  struct arg1 a1;
58  struct arg2 a2;
59  struct arg4 a4;
60  struct arg8 a8;
61  struct arg16 a16;
62  struct arg32 a32;
63  struct arg64 a64;
64  struct arg128 a128;
65 
66  int corres[] = { sizeof(struct arg1),
67  sizeof(struct arg1),
68  sizeof(struct arg2),
69  sizeof(struct arg4),
70  sizeof(struct arg8),
71  sizeof(struct arg16),
72  sizeof(struct arg32),
73  sizeof(struct arg128)};
74 
75  long long int * timeval = calloc(8, sizeof(double));
76  long long int * timept = calloc(8, sizeof(double));
77  int i,j;
78 
79  //for(i=0; i<MAX_SIZE; i++) {
80 
81  //Preparation
82  for(j=0; j<TURN; j++)
83  fctpt((void*)&a1);
84  for(j=0; j<TURN; j++)
85  fctval1(a1);
86  for(j=0; j<TURN; j++)
87  fctpt((void*)&a4);
88 
89 
90  // struct arg1
91  start_timer(t);
92  for(j=0; j<TURN; j++)
93  fctpt((void*)&a1);
94  timept[0] += (stop_timer(t)*1000/TURN);
95  start_timer(t);
96  for(j=0; j<TURN; j++)
97  fctval1(a1);
98  timeval[0] += (stop_timer(t)*1000/TURN);
99 
100  // struct arg2
101  start_timer(t);
102  for(j=0; j<TURN; j++)
103  fctpt((void*)&a2);
104  timept[1] += (stop_timer(t)*1000/TURN);
105  start_timer(t);
106  for(j=0; j<TURN; j++)
107  fctval2(a2);
108  timeval[1] += (stop_timer(t)*1000/TURN);
109 
110  // struct arg4
111  start_timer(t);
112  for(j=0; j<TURN; j++)
113  fctpt((void*)&a4);
114  timept[2] += (stop_timer(t)*1000/TURN);
115  start_timer(t);
116  for(j=0; j<TURN; j++)
117  fctval4(a4);
118  timeval[2] += (stop_timer(t)*1000/TURN);
119 
120  // struct arg8
121  start_timer(t);
122  for(j=0; j<TURN; j++)
123  fctpt((void*)&a8);
124  timept[3] += (stop_timer(t)*1000/TURN);
125  start_timer(t);
126  for(j=0; j<TURN; j++)
127  fctval8(a8);
128  timeval[3] += (stop_timer(t)*1000/TURN);
129 
130  // struct arg16
131  start_timer(t);
132  for(j=0; j<TURN; j++)
133  fctpt((void*)&a16);
134  timept[4] += (stop_timer(t)*1000/TURN);
135  start_timer(t);
136  for(j=0; j<TURN; j++)
137  fctval16(a16);
138  timeval[4] += (stop_timer(t)*1000/TURN);
139 
140  // struct arg32
141  start_timer(t);
142  for(j=0; j<TURN; j++)
143  fctpt((void*)&a32);
144  timept[5] += (stop_timer(t)*1000/TURN);
145  start_timer(t);
146  for(j=0; j<TURN; j++)
147  fctval32(a32);
148  timeval[5] += (stop_timer(t)*1000/TURN);
149 
150  // struct arg64
151  start_timer(t);
152  for(j=0; j<TURN; j++)
153  fctpt((void*)&a64);
154  timept[6] += (stop_timer(t)*1000/TURN);
155  start_timer(t);
156  for(j=0; j<TURN; j++)
157  fctval64(a64);
158  timeval[6] += (stop_timer(t)*1000/TURN);
159 
160  // struct arg128
161  start_timer(t);
162  for(j=0; j<TURN; j++)
163  fctpt((void*)&a128);
164  timept[7] += (stop_timer(t)*1000/TURN);
165  start_timer(t);
166  for(j=0; j<TURN; j++)
167  fctval128(a128);
168  timeval[7] += (stop_timer(t)*1000/TURN);
169  //}
170 
171  for(i=0; i<8; i++) {
172  write_record(pt_rec, corres[i], (long int) (timept[i]));//(MAX_SIZE)));
173  write_record(val_rec, corres[i], (long int) (timeval[i]));//(MAX_SIZE)));
174  }
175 
176  recorder_free(val_rec);
177  recorder_free(pt_rec);
178  timer_free(t);
179 
180  return EXIT_SUCCESS;
181 }
Definition: argfct.c:38
void fctval32(struct arg32 arg)
Definition: argfct.c:47
Definition: argfct.c:34
void fctval8(struct arg8 arg)
Definition: argfct.c:45
void timer_free(timer *t)
Retourne le temps en nanosecondes depuis le début de mesure dans t
Definition: benchmark.c:172
Definition: argfct.c:26
recorder écrit les temps dans un fichier .csv
Definition: benchmark.c:208
Definition: argfct.c:36
void fctval1(struct arg1 arg)
Definition: argfct.c:42
Definition: argfct.c:28
void write_record(recorder *rec, long int x, long int time)
Écris le temps time en correspondance avec x
Definition: benchmark.c:245
timer permet de mesurer le temps écoulé entre deux moments
Definition: benchmark.c:43
timer * t
Definition: memfork.c:25
void fctpt(void *arg)
Definition: argfct.c:40
Definition: argfct.c:30
int i
Definition: mutsem.c:43
void start_timer(timer *t)
Stoque le temps actuel comme début de la mesure dans t
Definition: benchmark.c:87
recorder * recorder_alloc(char *filename)
Alloue un recorder
Definition: benchmark.c:219
void fctval64(struct arg64 arg)
Definition: argfct.c:48
Definition: argfct.c:32
void fctval16(struct arg16 arg)
Definition: argfct.c:46
void recorder_free(recorder *rec)
Libère toutes les resources utilisées par rec
Definition: benchmark.c:263
timer * timer_alloc()
Alloue un timer
Definition: benchmark.c:63
#define TURN
Definition: argfct.c:19
void fctval128(struct arg128 arg)
Definition: argfct.c:49
Definition: argfct.c:24
long int stop_timer(timer *t)
Retourne le temps en nanosecondes depuis le début de mesure dans t
Definition: benchmark.c:133
void fctval2(struct arg2 arg)
Definition: argfct.c:43
void fctval4(struct arg4 arg)
Definition: argfct.c:44