From b53be4975097c6badeeab542d466856ce322bf0a Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 25 Dec 2008 20:06:33 +0100 Subject: [PATCH] Avoid use of sys/times.h header when not available --- test_approx.c | 31 ++++++++++++++++++++++++++++--- test_bound.cc | 31 ++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/test_approx.c b/test_approx.c index f32a2c8..54ff386 100644 --- a/test_approx.c +++ b/test_approx.c @@ -1,11 +1,36 @@ #include #include -#include #include #include "verify.h" #include "argp.h" #include "progname.h" +#ifdef HAVE_SYS_TIMES_H + +#include + +typedef clock_t my_clock_t; + +static my_clock_t time_diff(struct tms *before, struct tms *after) +{ + return after->tms_utime - before->tms_utime; +} + +#else + +typedef int my_clock_t; + +struct tms {}; +static void times(struct tms* time) +{ +} +static my_clock_t time_diff(struct tms *before, struct tms *after) +{ + return 0; +} + +#endif + struct { int sign; int method; @@ -90,7 +115,7 @@ struct result_data { Value n; double RE_sum[nr_methods]; - clock_t ticks[nr_methods]; + my_clock_t ticks[nr_methods]; size_t size[nr_methods]; }; @@ -318,7 +343,7 @@ void handle(FILE *in, struct result_data *result, struct verify_options *options times(&st_cpu); EP[i] = barvinok_enumerate_with_options(A, C, options->barvinok); times(&en_cpu); - result->ticks[i] = en_cpu.tms_utime - st_cpu.tms_utime; + result->ticks[i] = time_diff(&en_cpu, &st_cpu); /* print_evalue(stdout, EP[i], param_name); */ diff --git a/test_bound.cc b/test_bound.cc index 9539b73..6d50907 100644 --- a/test_bound.cc +++ b/test_bound.cc @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -12,6 +11,32 @@ #include "verify.h" #include "range.h" +#ifdef HAVE_SYS_TIMES_H + +#include + +typedef clock_t my_clock_t; + +static my_clock_t time_diff(struct tms *before, struct tms *after) +{ + return after->tms_utime - before->tms_utime; +} + +#else + +typedef int my_clock_t; + +struct tms {}; +static void times(struct tms* time) +{ +} +static my_clock_t time_diff(struct tms *before, struct tms *after) +{ + return 0; +} + +#endif + using std::cout; using std::cerr; using std::endl; @@ -64,7 +89,7 @@ struct result_data { Value n; double RE_sum[nr_methods]; - clock_t ticks[nr_methods]; + my_clock_t ticks[nr_methods]; size_t size[nr_methods]; }; @@ -250,7 +275,7 @@ void handle(FILE *in, struct result_data *result, struct verify_options *options } } times(&en_cpu); - result->ticks[i] = en_cpu.tms_utime - st_cpu.tms_utime; + result->ticks[i] = time_diff(&en_cpu, &st_cpu); if (options->barvinok->verbose) for (int j = 0; j < 2; ++j) cerr << *pl[2*i+j] << endl; -- 2.11.4.GIT