Jeroen Demeyer on Mon, 04 Oct 2004 21:48:47 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Timing: patch to time extern() and system() |
Technical note: It works with getrusage() as well as times(). Remark that we only count the so called "user time", not the "system time". This means we only get the time spent by the actual program, not e.g. the loading of the program by the OS. Also, if the program does nothing, that time will not be counted. Example: system("sleep 1") takes 0 ms.
Karim, could you commit this? Cheers, Jeroen
Index: src/language/init.c =================================================================== RCS file: /home/cvs/pari/src/language/init.c,v retrieving revision 1.241 diff -u -r1.241 init.c --- src/language/init.c 26 Sep 2004 16:02:18 -0000 1.241 +++ src/language/init.c 4 Oct 2004 19:25:39 -0000 @@ -1907,11 +1907,11 @@ TIMER(pari_timer *T) { struct tms t; times(&t); - return _get_time(T, t.tms_utime, + return _get_time(T, t.tms_utime + t.tms_cutime, #ifdef _SC_CLK_TCK - sysconf(_SC_CLK_TCK) + sysconf(_SC_CLK_TCK) #else - CLK_TCK + CLK_TCK #endif ); } @@ -1922,14 +1922,17 @@ long TIMER(pari_timer *T) { - struct rusage r; - struct timeval t; + struct rusage r0; + struct rusage r1; long delay; - getrusage(0,&r); t = r.ru_utime; - delay = 1000 * (t.tv_sec - T->s) + (t.tv_usec - T->us) / 1000; - T->us = t.tv_usec; - T->s = t.tv_sec; return delay; + getrusage(RUSAGE_SELF, &r0); + getrusage(RUSAGE_CHILDREN, &r1); + delay = 1000 * (r0.ru_utime.tv_sec + r1.ru_utime.tv_sec - T->s) + + (r0.ru_utime.tv_usec + r1.ru_utime.tv_usec - T->us) / 1000; + T->us = r0.ru_utime.tv_usec + r1.ru_utime.tv_usec; + T->s = r0.ru_utime.tv_sec + r1.ru_utime.tv_sec; + return delay; } #elif USE_FTIME Index: config/has_getrusage.c =================================================================== RCS file: /home/cvs/pari/config/has_getrusage.c,v retrieving revision 1.2 diff -u -r1.2 has_getrusage.c --- config/has_getrusage.c 7 Jan 2003 20:33:19 -0000 1.2 +++ config/has_getrusage.c 4 Oct 2004 19:25:39 -0000 @@ -4,4 +4,4 @@ #include <sys/time.h> #include <sys/resource.h> #include <unistd.h> -main(){ struct rusage a; printf("%d",getrusage(0,&a));} +main(){ struct rusage a; printf("%d",getrusage(RUSAGE_SELF,&a));}