1. Strange time() behaviour
- Posted by Leonardo Cecchi <leonardoce at interfree.it> Apr 02, 2007
- 533 views
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:
procedure test_time() atom timer, exit_code timer=time() exit_code=system_exec("sleep 2s", 2) ? time()-timer end procedure test_time()
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. Thanks, Leonardo
2. Re: Strange time() behaviour
- Posted by Igor Kachan <kinz at peterlink.ru> Apr 07, 2007
- 529 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. > Thanks, > > Leonardo Works OK here, I've got 2.02. EU 3.0.2 and EU 2.5 on Linux Mandrake 10.0. From procedure or from top level, from ed.ex or from command line - same results, I could not reproduce that strange your result. Regards, Igor Kachan kinz at peterlink.ru
3. Re: Strange time() behaviour
- Posted by Hayden McKay <hmck1 at dodo.com.au> Apr 08, 2007
- 527 views
Igor Kachan wrote: > > 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. > > Thanks, > > > > Leonardo > > Works OK here, I've got 2.02. > > EU 3.0.2 and EU 2.5 on Linux Mandrake 10.0. > > From procedure or from top level, > from ed.ex or from command line - same results, > I could not reproduce that strange your result. > > Regards, > Igor Kachan > kinz at peterlink.ru I'm running Windows 98se plus; ex.exe testtime.e ~0.05
4. Re: Strange time() behaviour
- Posted by Hayden McKay <hmck1 at dodo.com.au> Apr 08, 2007
- 519 views
oops... i'm not useing linux I should have tried;
procedure test_time() atom timer, exit_code timer=time() sleep(2) ? time()-timer end procedure test_time()
my stupid nb, returns ~2 secs
5. Re: Strange time() behaviour
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Apr 08, 2007
- 535 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
6. Re: Strange time() behaviour
- Posted by Leonardo Cecchi <leonardoce at interfree.it> Apr 08, 2007
- 544 views
I think you are right. In another computer, with Suse 8 (kernel 2.4.19), I have the right result. With Ubuntu 6.10 (kernel 2.6.17), I have the *wrong* result. So I tried compiling the following C program: #include <stdio.h> #include <unistd.h> #include <time.h> int main(int argc, char **argv) { long int clk_tck=sysconf(_SC_CLK_TCK); printf("CLOCKS_PER_SEC: %li\n", CLOCKS_PER_SEC); #ifdef CLK_TCK printf("CLK_TCK defined: %li\n", CLK_TCK); #else printf("CLK_TCK from sysconf: %li\n", clk_tck); #endif#ifndef CLK_TCK #define CLK_TCK CLOCKS_PER_SEC #endif } With Ubuntu 6.10 kernel 2.6.17 it says: $ ./testclk CLOCKS_PER_SEC: 1000000 CLK_TCK from sysconf: 100 With Suse 8 kernel 2.4.19: $ ./testclk CLOCKS_PER_SEC: 1000000 CLK_TCK defined: 100 So I think the problem is the definition of the macro CLK_TCK. In fact, in the global.h file, I found the following instructions: #ifndef CLK_TCK #define CLK_TCK CLOCKS_PER_SEC #endif But, with ubuntu, the value of CLK_TCK is diffent from the value of CLOCKS_PER_SEC. Thanks, Leonardo
7. Re: Strange time() behaviour
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Apr 08, 2007
- 552 views
Leonardo Cecchi wrote: > > So I think the problem is the definition of the macro CLK_TCK. > In fact, in the global.h file, I found the following instructions: > > #ifndef CLK_TCK > #define CLK_TCK CLOCKS_PER_SEC > #endif > > But, with ubuntu, the value of CLK_TCK is diffent > from the value of CLOCKS_PER_SEC. > Yep. I clearly didn't understand what was going on with this before, when I created this macro. I've fixed it up in the repository now. It doesn't define CLK_TCK at all, but rather fixes the value of clk_tck to use sysconf(_SC_CLK_TCK) instead. There was one place in be_execute.c that used the macro instead of the value, and I had to update compile.e to use this, too. I now get the correct result with Ubuntu. Matt
8. Re: Strange time() behaviour
- Posted by Leonardo Cecchi <leonardoce at interfree.it> Apr 08, 2007
- 559 views
Hi, I've tested the new SVN version with Ubuntu (kernel 2.6.17) and Suse (kernel 2.4.19) and it's all ok. Thanks, Leonardo