Skip to content

Instantly share code, notes, and snippets.

@nclv
Created October 12, 2020 13:28
Show Gist options
  • Save nclv/bf1518d9255f8c9978e312eefe380949 to your computer and use it in GitHub Desktop.
Save nclv/bf1518d9255f8c9978e312eefe380949 to your computer and use it in GitHub Desktop.
Module pour effectuer l'analyse temporelle de plusieurs fonctions avec des arguments différents
#ifndef _CONST_
#define _CONST_
#define n (1000)
#define m (1000)
#define RANGE (100)
typedef double E;
#endif
#include "timing.h"
#include <stdio.h>
#include <time.h>
void generic_fn_execution_time(t_args_wrapper *args_wrapper,
void (*generic_fn)(t_args_wrapper *)) {
static clock_t start, end;
static double cpu_time_used;
start = clock();
(*generic_fn)(args_wrapper);
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("CPU time used: %lf\n", cpu_time_used);
}
#ifndef _TIMING_
#define _TIMING_
#include <stdlib.h>
#include "const.h"
typedef struct mergesort_args {
size_t _n;
E *array;
E *buffer;
} t_mergesort_args;
typedef struct transposition_args {
double **matrix;
double **result;
} t_transposition_args;
typedef struct array2d_min_max_args {
double **matrix;
double *line;
double *col;
} t_array2d_min_max_args;
// Wrapper
typedef struct args_wrapper {
t_mergesort_args *mergesort_args;
t_transposition_args *transposition_args;
t_array2d_min_max_args *array2d_min_max_args;
} t_args_wrapper;
extern void generic_fn_execution_time(t_args_wrapper *args_wrapper,
void (*generic_fn)(t_args_wrapper *));
#endif
@nclv
Copy link
Author

nclv commented Oct 12, 2020

Petit exemple d'utilisation

void generic_transpose_ligne(t_args_wrapper *args_wrapper) {
    if (args_wrapper != NULL) {
        t_transposition_args *transposition_args = args_wrapper->transposition_args;
        if (transposition_args != NULL) {
            transpose_ligne(transposition_args->matrix, transposition_args->result);
        }
    }
}

void generic_transpose_block(t_args_wrapper *args_wrapper) {
    if (args_wrapper != NULL) {
        t_transposition_args *transposition_args = args_wrapper->transposition_args;
        if (transposition_args != NULL) {
            transpose_block(transposition_args->matrix, transposition_args->result);
        }
    }
}

t_transposition_args transposition_args = {.matrix = A, .result = B};
t_args_wrapper args_wrapper = {
                                   .mergesort_args = NULL,
                                   .transposition_args = &transposition_args,
                                   .array2d_min_max_args = NULL
};
printf("\ntranspose_ligne\n");
generic_fn_execution_time(&args_wrapper, generic_transpose_ligne);
printf("\ntranspose_block\n");
generic_fn_execution_time(&args_wrapper, generic_transpose_block);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment