#include #include #include #include #include #include #include #define PLSIZE 63 int z=0; //ce bloc de code vient d'un exercice de tp que j'ai recuperer int set_signal_handler(int signo, void (*handler)(int)) { struct sigaction sa; sa.sa_handler = handler; // call `handler` on signal sigemptyset(&sa.sa_mask); // don't block other signals in handler sa.sa_flags = SA_RESTART; // restart system calls return sigaction(signo, &sa, NULL); } void sig_alarm(int signum){ printf("nombre de tests actuellement passes : %d\n",z); alarm(1); } struct lst { struct lst * next; long int payload[PLSIZE]; } l; struct lst * mkws(int size) { int i,j; struct lst * ws0,*ws; if (size == 0) return NULL; srand(time(0)); ws = calloc(1,sizeof(struct lst)); ws->next = NULL; for (i=0;ipayload[i]=(rand())%2; for (j=1;jpayload[i]=(rand())%2; ws->next = ws0; } return ws; } int main(int argc, char ** argv) { struct lst * ws, * ws0; long long int start, end, dif; long int i, x, size, it; if (argc != 3) { printf("Usage: %s \n",argv[0]); exit(1); } set_signal_handler(SIGALRM,sig_alarm); alarm(1); size=strtol(argv[1],NULL,0); ws = mkws(size); if (ws == NULL) { printf("NIL list created...\n"); exit(1); } it = strtol(argv[2],NULL,0); start = __rdtsc(); for (i = 0; i < it; i++) { ws0 = ws; while (ws0 != NULL) { x = ws0->payload[3]; x++; z++; ws0 = ws0->next; } } end = __rdtsc(); dif = end - start; printf("Cycles/element = %lf\n", ((double) dif)/((double) size*it)); exit(0); }