1. Strange time() behaviour

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

new topic     » topic index » view message » categorize

2. Re: Strange time() behaviour

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Strange time() behaviour

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Strange time() behaviour

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

new topic     » goto parent     » topic index » view message » categorize

5. Re: Strange time() behaviour

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

new topic     » goto parent     » topic index » view message » categorize

6. Re: Strange time() behaviour

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

new topic     » goto parent     » topic index » view message » categorize

7. Re: Strange time() behaviour

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

new topic     » goto parent     » topic index » view message » categorize

8. Re: Strange time() behaviour

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu