[GiNaC-list] small portability fix
Sheplyakov Alexei
varg at theor.jinr.ru
Wed Nov 2 11:53:57 CET 2005
Hello,
On Tue, Nov 01, 2005 at 09:04:01PM +0100, Richard B. Kreckel wrote:
> Thanks for submitting a patch. However, your patch trades the
> measurement of used system time for the measurement of elapsed
> (physical) time.
Yes, since (AFAIK) there is no portable way to measure the former.
> I don't think that's what we want.
OK, here is another patch. It uses getrusage() whenever available
and std::clock() as a last resort.
--
All science is either physics or stamp collecting.
-------------- next part --------------
Index: acinclude.m4
===================================================================
RCS file: /home/cvs/GiNaC/acinclude.m4,v
retrieving revision 1.21
diff -r1.21 acinclude.m4
102a103,123
>
> AC_DEFUN([GINAC_HAVE_RUSAGE],
> [AC_CACHE_CHECK([whether struct rusage is declared in <sys/resource.h>],
> ac_cv_have_rusage,
> [AC_TRY_COMPILE([#include <sys/times.h>
> #include <sys/resource.h>],
> [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 <sys/resource.h>])
> fi
> AC_SUBST(CONFIG_RUSAGE)
> ])
>
>
Index: configure.ac
===================================================================
RCS file: /home/cvs/GiNaC/configure.ac,v
retrieving revision 1.21.2.5
diff -r1.21.2.5 configure.ac
24c24,25
< AC_CONFIG_HEADERS(config.h)
---
> AC_CONFIG_AUX_DIR(config)
> AC_CONFIG_HEADERS([config/config.h])
84a86
> GINAC_HAVE_RUSAGE
113a116,118
> if test "x$CONFIG_RUSAGE" = "xno"; then
> AC_CHECK_HEADER(ctime, , GINAC_ERROR([The standard <ctime> header file could not be found.]))
> fi
Index: check/timer.cpp
===================================================================
RCS file: /home/cvs/GiNaC/check/timer.cpp,v
retrieving revision 1.7.4.3
diff -r1.7.4.3 timer.cpp
23c23,26
< #include <sys/time.h>
---
> #ifdef HAVE_CONFIG_H
> #include "config.h"
> #endif
> #ifdef HAVE_RUSAGE
25a29,32
> #include <sys/time.h>
> #else
> #include <ctime>
> #endif
28a36
> #ifdef HAVE_RUSAGE
69a78,116
> #else /* no getrusage() */
>
> using std::clock;
> timer::timer() : on(false)
> {
> used1 = clock();
> used2 = used1;
> }
>
> void timer::start()
> {
> on = true;
> used1 = clock();
> used2 = used1;
> }
>
> void timer::stop()
> {
> on = false;
> used2 = clock();
> }
>
> void timer::reset()
> {
> used1 = clock();
> used2 = used1;
> }
>
> double timer::read()
> {
> double elapsed;
> if (running())
> used2 = clock();
> elapsed = (used2 - used1)/CLOCKS_PER_SEC;
> // Results more accurate than 10ms are pointless:
> return 0.01*int(elapsed*100+0.5);
> }
> #endif /* HAVE_RUSAGE */
>
Index: check/timer.h
===================================================================
RCS file: /home/cvs/GiNaC/check/timer.h,v
retrieving revision 1.3.4.2
diff -r1.3.4.2 timer.h
25a26,29
> #ifdef HAVE_CONFIG_H
> #include "config.h"
> #endif
> #ifdef HAVE_RUSAGE
26a31,33
> #else
> #include <ctime>
> #endif
37a45
> #ifdef HAVE_RUSAGE
38a47,49
> #else
> std::clock_t used1, used2;
> #endif
Index: ginsh/ginsh_parser.yy
===================================================================
RCS file: /home/cvs/GiNaC/ginsh/ginsh_parser.yy,v
retrieving revision 1.77.2.4
diff -r1.77.2.4 ginsh_parser.yy
31c31
<
---
> #ifdef HAVE_RUSAGE
32a33,35
> #else
> #include <ctime>
> #endif
63a67
> #ifdef HAVE_RUSAGE
64a69,83
> #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
213,219c232
< | 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 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20051102/7eb711cb/attachment.pgp
More information about the GiNaC-list
mailing list