evalue_isl.c: extract_base: rename "dim" parameter to "space"
[barvinok.git] / zsolve / cputime.c
blobd9e4869c78c1beeca6b831fdaee097c314a967b0
1 /*
2 4ti2 -- A software package for algebraic, geometric and combinatorial
3 problems on linear spaces.
5 Copyright (C) 2006 4ti2 team.
6 Main author(s): Matthias Walter.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "cputime.h"
25 #include "defs.h"
27 #include <assert.h>
28 #include <stdlib.h>
29 #ifdef _POSIX_TIMERS
30 #include <sys/time.h>
31 #include <sys/resource.h>
32 #endif
33 #include <time.h>
35 // //
37 double getCPUTime()
39 #ifdef _POSIX_TIMERS
40 struct rusage usage;
42 getrusage(RUSAGE_SELF, &usage);
44 return (double)usage.ru_utime.tv_sec + 1e-6*usage.ru_utime.tv_usec;
45 #else
46 return (double) clock() / CLOCKS_PER_SEC;
47 #endif
50 // //
52 void fprintCPUTime(FILE *stream, CPUTime time)
54 if (time>=86400.0)
55 fprintf(stream, "%.2f days", time / 86400.0);
56 else if (time>=3600.0)
57 fprintf(stream, "%.2f hours", time / 3600.0);
58 else if (time>=60.0)
59 fprintf(stream, "%.2f mins", time / 60.0);
60 else
61 fprintf(stream, "%.2f secs", time);
64 // //
66 void printCPUTime(CPUTime time)
68 fprintCPUTime(stdout, time);
71 // //