Re: Strange time() behaviour
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Apr 08, 2007
- 534 views
Leonardo Cecchi wrote: > > In the euphoria reference library I read that time() > "Return the number of seconds since some fixed point in the past.". > > But, if I execute the following code: > > }}} <eucode> > procedure test_time() > atom timer, exit_code > > timer=time() > exit_code=system_exec("sleep 2s", 2) > ? time()-timer > end procedure > > test_time() > </eucode> {{{ > > I obtain: > > $ exu testtime.e > 0.0002019999999 > > I think the right result should be a number bigger than 2. > Where I'm wrong? > I'm working with Euphoria 3.0.2/Linux and the result > is the same with Euphoria SVN. I get the same result. I think this is a consequence of CLK_TICK being obsolete. See here for some detail: http://www.die.net/doc/linux/man/man2/times.2.html The relevant code is in be_machine.c: double current_time() /* return value for time() function */ { #ifdef ELINUX struct tms buf; #endif if (clock_frequency == 0.0) { /* no handler */ return (double) #ifdef ELINUX times(&buf) / clk_tck #else clock() / (double)clocks_per_sec #endif + clock_adjust; } else { /* our handler is installed */ return base_time + our_clock_ticks / clock_frequency; } } Matt