*
This commit is contained in:
19
SCR3.1/devoir27/ex2/helpers.c
Normal file
19
SCR3.1/devoir27/ex2/helpers.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "helpers.h"
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
double tstamp(void) {
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
|
||||
}
|
||||
|
||||
|
7
SCR3.1/devoir27/ex2/helpers.h
Normal file
7
SCR3.1/devoir27/ex2/helpers.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _HELPERS_H
|
||||
#define _HELPERS_H
|
||||
|
||||
int set_signal_handler(int signo, void (*handler)(int));
|
||||
double tstamp(void);
|
||||
|
||||
#endif
|
95
SCR3.1/devoir27/ex2/vcachetest.c
Normal file
95
SCR3.1/devoir27/ex2/vcachetest.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <x86intrin.h>
|
||||
#include <signal.h>
|
||||
#include "helpers.c"
|
||||
#include "helpers.h"
|
||||
|
||||
|
||||
#define PLSIZE 63
|
||||
|
||||
|
||||
|
||||
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;i<PLSIZE;i++)
|
||||
ws->payload[i]=(rand())%2;
|
||||
|
||||
for (j=1;j<size;j++) {
|
||||
ws0=ws;
|
||||
ws = calloc(1,sizeof(struct lst));
|
||||
if (ws==NULL) {
|
||||
fprintf(stderr,"Can't add element...\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0;i<PLSIZE;i++)
|
||||
ws->payload[i]=(rand())%2;
|
||||
ws->next = ws0;
|
||||
}
|
||||
return ws;
|
||||
}
|
||||
|
||||
long int z = 0;
|
||||
|
||||
void kill_prg(int){
|
||||
printf("Nombre de tests effectués: %ld\n", z);
|
||||
}
|
||||
|
||||
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 <list size> <iterations>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
set_signal_handler(SIGTSTP, &kill_prg);
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user