Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
86 user(s) are online (58 user(s) are browsing Forums)

Members: 2
Guests: 84

VooDoo, sofistisoftware, more...

Headlines

 
  Register To Post  

timemeasure function give 0ms ?
Home away from home
Home away from home


See User information
There is test code:

// ppc-amigaos-g++ -D__USE_OLDTIMEVAL__ test_timemeasuer.c

#include <stdio.h>
#include <proto/dos.h>

unsigned int GetTimeStamp()
{
    
timeval tNow;
    
gettimeofday(&tNowNULL);
    return ((double)
tNow.tv_sec)*1000.0+((double)tNow.tv_usec)/1000.0;
}



int main()
{

int nStartTime=GetTimeStamp();

IDOS->Delay(500);

printf("test time %d ms",GetTimeStamp()-nStartTime);

}


I compile it like

Quote:

ppc-amigaos-g++ -D__USE_OLDTIMEVAL__ test_timemeasuer.c


On running, it wait for some time when Delay() call happens, and then, give me in return 0 ms in printf.

Why ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: timemeasure function give 0ms ?
Not too shy to talk
Not too shy to talk


See User information

Probably because your time stamp calculation overflows. Your GetTimeStamp() function always returns -1.

It works better if you use (tNow.tv_sec % 86400), but might give wrong results around midnight.

Go to top
Re: timemeasure function give 0ms ?
Just popping in
Just popping in


See User information
@thomas

I would say he's returning seconds and the wait is less than one

Go to top
Re: timemeasure function give 0ms ?
Quite a regular
Quite a regular


See User information
@Ami603

See AutoDocs/dos - it is ten seconds.

Go to top
Re: timemeasure function give 0ms ?
Home away from home
Home away from home


See User information
@Ami604,Thematic
Yeah it 10 seconds

@Thomas

Once i get rid of double computation, like replacing return string on that:

Quote:

return tNow.tv_sec*1000+tNow.tv_usec/1000;


Then all works. But that code (with double), for sure works on linux and win32.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: timemeasure function give 0ms ?
Just popping in
Just popping in


See User information
@kas1e

Does ((double)tNow.tv_sec)) really convert from whatever type tv_sec is, to a proper double? Is it perhaps just casting whatever is there and trying to interpret is as a double?

Maintainer and developer for Jamiga2 - Java for Amiga
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project