Index: configure.ac =================================================================== RCS file: /home/cvs/GiNaC/configure.ac,v retrieving revision 1.21.2.6 diff -u -r1.21.2.6 configure.ac --- configure.ac 12 Apr 2006 16:23:01 -0000 1.21.2.6 +++ configure.ac 14 Jul 2006 17:31:16 -0000 @@ -82,6 +82,7 @@ dnl Check for stuff needed for building the GiNaC interactive shell (ginsh). AC_CHECK_HEADERS(unistd.h) +GINAC_HAVE_RUSAGE AC_CHECK_HEADERS(readline/readline.h readline/history.h) if test "x${ac_cv_header_readline_readline_h}" != "xyes" -o "x${ac_cv_header_readline_history_h}" != "xyes"; then GINAC_WARNING([I could not find the headers for libreadline (needed for building ginsh).]) @@ -111,6 +112,9 @@ AC_CHECK_HEADER(stdexcept, , GINAC_ERROR([The standard header file could not be found.])) AC_CHECK_HEADER(algorithm, , GINAC_ERROR([The standard header file could not be found.])) AC_CHECK_HEADER(limits, , GINAC_ERROR([The standard header file could not be found.])) +if test "x$CONFIG_RUSAGE" = "xno"; then + AC_CHECK_HEADER(ctime, , GINAC_ERROR([The standard header file could not be found.])) +fi dnl We need to have Bruno Haible's CLN installed. dnl (CLN versions >= 1.1.0 must have installed cln.m4 at a visible place, Index: acinclude.m4 =================================================================== RCS file: /home/cvs/GiNaC/acinclude.m4,v retrieving revision 1.21 diff -u -r1.21 acinclude.m4 --- acinclude.m4 5 Jul 2004 15:56:28 -0000 1.21 +++ acinclude.m4 14 Jul 2006 17:31:16 -0000 @@ -43,6 +43,10 @@ dnl libtermcap is being phased out. AC_DEFUN([GINAC_TERMCAP], [LIBTERMCAP= +case $host_os in +*mingw32*) dnl termcap library is not necessary on this platform +;; +*) AC_CHECK_FUNCS(tgetent) if test "x$ac_cv_func_tgetent" = "xyes"; then : @@ -52,6 +56,8 @@ AC_CHECK_LIB(termcap, tgetent, LIBTERMCAP="-ltermcap") fi fi +;; +esac AC_SUBST(LIBTERMCAP) ]) @@ -100,3 +106,22 @@ fi echo "Configuration of GiNaC $VERSION done. Now type \"make\"." fi]) + +AC_DEFUN([GINAC_HAVE_RUSAGE], +[AC_CACHE_CHECK([whether struct rusage is declared in ], +ac_cv_have_rusage, + [AC_TRY_COMPILE([#include + #include ], + [struct rusage resUsage; + getrusage(RUSAGE_SELF, &resUsage); + return 0;], + [ac_cv_have_rusage=yes], + [ac_cv_have_rusage=no]) +]) +CONFIG_RUSAGE="no" +if test "$ac_cv_have_rusage" = yes; then + CONFIG_RUSAGE="yes" + AC_DEFINE(HAVE_RUSAGE,,[define if struct rusage declared in ]) +fi +AC_SUBST(CONFIG_RUSAGE) +]) Index: check/Makefile.am =================================================================== RCS file: /home/cvs/GiNaC/check/Makefile.am,v retrieving revision 1.31 diff -u -r1.31 Makefile.am --- check/Makefile.am 20 Aug 2003 18:01:35 -0000 1.31 +++ check/Makefile.am 14 Jul 2006 17:31:16 -0000 @@ -2,6 +2,7 @@ TESTS = run_exams run_checks run_times check_PROGRAMS = exams checks times +TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) srcdir=$(srcdir) checks_SOURCES = check_numeric.cpp check_inifcns.cpp check_matrices.cpp \ check_lsolve.cpp genex.cpp checks.cpp checks.h Index: check/exam_archive.cpp =================================================================== RCS file: /home/cvs/GiNaC/check/exam_archive.cpp,v retrieving revision 1.13.4.2 diff -u -r1.13.4.2 exam_archive.cpp --- check/exam_archive.cpp 1 May 2005 18:12:42 -0000 1.13.4.2 +++ check/exam_archive.cpp 14 Jul 2006 17:31:16 -0000 @@ -54,12 +54,12 @@ archive ar; ar.archive_ex(e, "expr 1"); { - std::ofstream fout("exam.gar"); + std::ofstream fout("exam.gar", std::ios_base::binary); fout << ar; } ar.clear(); { - std::ifstream fin("exam.gar"); + std::ifstream fin("exam.gar", std::ios_base::binary); fin >> ar; } f = ar.unarchive_ex(lst(x, y, mu, dim), "expr 1"); Index: check/run_checks =================================================================== RCS file: /home/cvs/GiNaC/check/run_checks,v retrieving revision 1.4 diff -u -r1.4 run_checks --- check/run_checks 13 Mar 2000 14:14:21 -0000 1.4 +++ check/run_checks 14 Jul 2006 17:31:16 -0000 @@ -1,4 +1,4 @@ #! /bin/sh echo "GiNaC will now run through some rather costly random consistency checks:" -./checks 2>checks.out +./checks${EXEEXT} 2>checks.out cmp ${srcdir}/checks.ref checks.out Index: check/run_exams =================================================================== RCS file: /home/cvs/GiNaC/check/run_exams,v retrieving revision 1.1 diff -u -r1.1 run_exams --- check/run_exams 29 Feb 2000 14:28:23 -0000 1.1 +++ check/run_exams 14 Jul 2006 17:31:16 -0000 @@ -1,4 +1,4 @@ #! /bin/sh echo "GiNaC will now take an exam with specific input (like a pupils' exam):" -./exams 2>exams.out +./exams${EXEEXT} 2>exams.out cmp ${srcdir}/exams.ref exams.out Index: check/run_times =================================================================== RCS file: /home/cvs/GiNaC/check/run_times,v retrieving revision 1.1 diff -u -r1.1 run_times --- check/run_times 29 Feb 2000 14:28:23 -0000 1.1 +++ check/run_times 14 Jul 2006 17:31:16 -0000 @@ -1,4 +1,4 @@ #! /bin/sh echo "GiNaC will now run through some basic timings:" -./times 2>times.out +./times${EXEEXT} 2>times.out cmp ${srcdir}/times.ref times.out Index: check/timer.cpp =================================================================== RCS file: /home/cvs/GiNaC/check/timer.cpp,v retrieving revision 1.7.4.3 diff -u -r1.7.4.3 timer.cpp --- check/timer.cpp 1 Nov 2005 21:05:15 -0000 1.7.4.3 +++ check/timer.cpp 14 Jul 2006 17:31:16 -0000 @@ -20,51 +20,80 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_RUSAGE #include #include +#include +#else +#include +#endif #include "timer.h" timer::timer() : on(false) { +#ifdef HAVE_RUSAGE getrusage(RUSAGE_SELF, &used1); used2.ru_utime = used1.ru_utime; used2.ru_stime = used1.ru_stime; +#else + used1 = clock(); + used2 = used1; +#endif } void timer::start() { on = true; +#ifdef HAVE_RUSAGE getrusage(RUSAGE_SELF, &used1); used2.ru_utime = used1.ru_utime; used2.ru_stime = used1.ru_stime; +#else + used1 = clock(); + used2 = used1; +#endif } void timer::stop() { on = false; +#ifdef HAVE_RUSAGE getrusage(RUSAGE_SELF, &used2); +#else + used2 = clock(); +#endif } void timer::reset() { +#ifdef HAVE_RUSAGE getrusage(RUSAGE_SELF, &used1); used2.ru_utime = used1.ru_utime; used2.ru_stime = used1.ru_stime; +#else + used1 = clock(); + used2 = used1; +#endif } double timer::read() { - double elapsed; +#ifdef HAVE_RUSAGE if (running()) getrusage(RUSAGE_SELF, &used2); - elapsed = ((used2.ru_utime.tv_sec - used1.ru_utime.tv_sec) + - (used2.ru_stime.tv_sec - used1.ru_stime.tv_sec) + - (used2.ru_utime.tv_usec - used1.ru_utime.tv_usec) * 1e-6 + - (used2.ru_stime.tv_usec - used1.ru_stime.tv_usec) * 1e-6); - // Results more accurate than 10ms are pointless: - return 0.01*int(elapsed*100+0.5); + return ((used2.ru_utime.tv_sec - used1.ru_utime.tv_sec) + + (used2.ru_stime.tv_sec - used1.ru_stime.tv_sec) + + (used2.ru_utime.tv_usec - used1.ru_utime.tv_usec) * 1e-6 + + (used2.ru_stime.tv_usec - used1.ru_stime.tv_usec) * 1e-6); +#else + if (running()) + used2 = clock(); + return double(used2 - used1)/CLOCKS_PER_SEC; +#endif } bool timer::running() Index: check/timer.h =================================================================== RCS file: /home/cvs/GiNaC/check/timer.h,v retrieving revision 1.3.4.2 diff -u -r1.3.4.2 timer.h --- check/timer.h 1 May 2005 18:12:42 -0000 1.3.4.2 +++ check/timer.h 14 Jul 2006 17:31:16 -0000 @@ -23,7 +23,14 @@ #ifndef TIMER_H #define TIMER_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_RUSAGE #include +#else +#include +#endif class timer { public: @@ -35,7 +42,11 @@ bool running(); private: bool on; +#ifdef HAVE_RUSAGE struct rusage used1, used2; +#else + std::clock_t used1, used2; +#endif }; #endif // ndef TIMER_H Index: ginsh/ginsh_parser.yy =================================================================== RCS file: /home/cvs/GiNaC/ginsh/ginsh_parser.yy,v retrieving revision 1.77.2.5 diff -u -r1.77.2.5 ginsh_parser.yy --- ginsh/ginsh_parser.yy 22 Apr 2006 15:42:25 -0000 1.77.2.5 +++ ginsh/ginsh_parser.yy 14 Jul 2006 17:31:17 -0000 @@ -28,8 +28,11 @@ %{ #include "config.h" - +#ifdef HAVE_RUSAGE #include +#else +#include +#endif #if HAVE_UNISTD_H #include @@ -61,7 +64,23 @@ static ex exstack[3]; // Start and end time for the time() function +#ifdef HAVE_RUSAGE static struct rusage start_time, end_time; +#define START_TIMER getrusage(RUSAGE_SELF, &start_time); +#define STOP_TIMER getrusage(RUSAGE_SELF, &end_time); +#define PRINT_TIME_USED cout << \ + (end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) + \ + (end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) + \ + double(end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1e6 + \ + double(end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1e6 \ + << 's' << endl; +#else +static std::clock_t start_time, end_time; +#define START_TIMER start_time = std::clock(); +#define STOP_TIMER end_time = std::clock(); +#define PRINT_TIME_USED \ + cout << double(end_time - start_time)/CLOCKS_PER_SEC << 's' << endl; +#endif // Table of functions (a multimap, because one function may appear with different // numbers of parameters) @@ -210,13 +229,7 @@ } | T_REAL_SYMBOLS { symboltype = domain::real; } | T_COMPLEX_SYMBOLS { symboltype = domain::complex; } - | T_TIME {getrusage(RUSAGE_SELF, &start_time);} '(' exp ')' { - getrusage(RUSAGE_SELF, &end_time); - cout << (end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) + - (end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) + - double(end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1e6 + - double(end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1e6 << 's' << endl; - } + | T_TIME { START_TIMER } '(' exp ')' { STOP_TIMER PRINT_TIME_USED } | error ';' {yyclearin; yyerrok;} | error ':' {yyclearin; yyerrok;} ;