3 /* A crash few tests for the maxmin library */
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include "xbt/xbt_portability.h"
13 #include "surf/maxmin.h"
14 #include "xbt/sysdep.h" /* time manipulation for benchmarking */
18 double float_random(double max);
19 double float_random(double max)
21 return ((max * rand()) / (RAND_MAX + 1.0));
24 int int_random(int max);
25 int int_random(int max)
27 return (int) (((max * 1.0) * rand()) / (RAND_MAX + 1.0));
30 void test(int nb_cnst, int nb_var, int nb_elem);
31 void test(int nb_cnst, int nb_var, int nb_elem)
33 lmm_system_t Sys = NULL;
34 lmm_constraint_t *cnst = calloc(nb_cnst, sizeof(lmm_constraint_t));
35 lmm_variable_t *var = calloc(nb_var, sizeof(lmm_variable_t));
36 int *used = calloc(nb_cnst, sizeof(int));
39 Sys = lmm_system_new();
41 for (i = 0; i < nb_cnst; i++) {
42 cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
45 for (i = 0; i < nb_var; i++) {
46 var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
47 for (j = 0; j < nb_cnst; j++)
49 for (j = 0; j < nb_elem; j++) {
50 k = int_random(nb_cnst);
55 lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
60 date = xbt_os_time() * 1000000;
62 date = xbt_os_time() * 1000000 - date;
71 int main(int argc, char **argv)
76 date = xbt_os_time() * 1000000;
77 test(nb_cnst, nb_var, nb_elem);
78 printf("One shot execution time for a total of %d constraints, "
79 "%d variables with %d active constraint each : %lg microsecondes \n",
80 nb_cnst, nb_var, nb_elem, date);