update pet for compatibility with recent clangs
[barvinok.git] / randomtest.c
blobd6e24a2f05cf13364b6cc6c627230229b649f709
1 #include <assert.h>
2 #include <unistd.h>
3 #include <barvinok/util.h>
4 #include <barvinok/barvinok.h>
6 #ifdef HAVE_SYS_TIMES_H
8 #include <sys/times.h>
10 static void time_diff(struct tms *before, struct tms *after)
12 long ticks = sysconf(_SC_CLK_TCK);
13 printf("User: %g; Sys: %g\n",
14 (0.0 + after->tms_utime - before->tms_utime) / ticks,
15 (0.0 + after->tms_stime - before->tms_stime) / ticks);
18 #else
20 struct tms { int dummy; };
21 static void times(struct tms* time)
24 static void time_diff(struct tms *before, struct tms *after)
28 #endif
30 int main()
32 static const int size = 1000;
33 static const int loop = 10;
34 int i, j, d, r, c;
35 Matrix *M;
36 Polyhedron *P;
37 Value cm, cb;
38 struct tms tms_before, tms_between, tms_after;
39 value_init(cm);
40 value_init(cb);
42 for (d = 2; d < 10; ++d) {
43 M = Matrix_Alloc(2*d, 2+d);
44 for (r = 0; r < 2*d; ++r)
45 value_set_si(M->p[r][0], 1);
46 for (i = 0; i < loop; ++i) {
47 for (r = 0; r < 2*d; ++r) {
48 for (c = 1; c < 1+d; ++c) {
49 value_set_si(M->p[r][c], random_int(size));
51 value_set_si(M->p[r][d+1], random_int(2)+1);
53 P = Rays2Polyhedron(M, 2*d);
54 Polyhedron_Print(stdout, P_VALUE_FMT, P);
55 times(&tms_before);
56 manual_count(P, &cm);
57 times(&tms_between);
58 barvinok_count(P, &cb, 100);
59 times(&tms_after);
60 printf("manual: ");
61 value_print(stdout, P_VALUE_FMT, cm);
62 puts("");
63 time_diff(&tms_before, &tms_between);
64 printf("Barvinok: ");
65 value_print(stdout, P_VALUE_FMT, cb);
66 puts("");
67 time_diff(&tms_between, &tms_after);
68 assert(value_eq(cm, cb));
70 Matrix_Free(M);
72 value_clear(cm);
73 value_clear(cb);
74 return 0;