[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Feb 9 19:53:36 2003 
Subject:Re: (forwarded for Brian Logan) Poplog timers ... 
From:Waldek Hebisch 
Volume-ID:1030209.01 

A.Sloman@cs.bham.ac.uk wrote:
: Non-member submission from [Brian Logan <bsl@cs.nott.ac.uk>]
 
: I have been trying to write some procedures to time the execution of Poplog
: code.
 
: systime has fairly poor resolution (1/100th of a second), so I happily wrote
: some timing procedures using sys_timer and trap procedures.  This didn't
: work, and on closer reading of REF TIMES I discovered that the maximum
: resolution of the asynchronous trap procedures created by sys_time is also
: 1/100th of a second.

Traditionaly Unix (Linux included) uses 10ms clock tick, so most timers 
are restricted to low resolutions. However, on modern machines real time 
is measured quite accurately. Real time is given by 'gettimeofday()' 
function in C. I do not know if poplog has any built-in interface to this 
function by the following example (using exload) seem to work OK:
exload 'timer'

    (language C)
        gettimeofday(tv,tz):void
endexload;

/* Get system time in microseconds */
define microtime();
    lvars tv = initintvec(2);
    exacc gettimeofday(tv, 0);
    1000000*tv(1)+tv(2)
enddefine;

define fib(n);
   if n<2 then 1
   else fib(n-1)+fib(n-2)
   endif
enddefine;

lvars a, b;
microtime()->a;
a=>
fib(20) =>
microtime()->b;
b=>
b-a =>


  
--
                              Waldek Hebisch
hebisch@math.uni.wroc.pl    or hebisch@hera.math.uni.wroc.pl