Login
Username:

Password:

Remember me



Lost Password?

Register now!
Sections
Who's Online
80 user(s) are online (58 user(s) are browsing Forums)

Members: 1
Guests: 79

mufa, more...
Support us!
Recent OS4 Files
OS4Depot.net





timemeasure function give 0ms ?
Home away from home
Joined:
2007/9/11 11:31
From Russia
Posts: 4668
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!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: timemeasure function give 0ms ?
Not too shy to talk
Joined:
2006/11/26 17:45
Posts: 269

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.

   Report Go to top

Re: timemeasure function give 0ms ?
Just popping in
Joined:
2006/12/27 21:09
Posts: 54
@thomas

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

   Report Go to top

Re: timemeasure function give 0ms ?
Quite a regular
Joined:
2007/2/27 10:47
From Gravity well
Posts: 613
@Ami603

See AutoDocs/dos - it is ten seconds.

   Report Go to top

Re: timemeasure function give 0ms ?
Home away from home
Joined:
2007/9/11 11:31
From Russia
Posts: 4668
@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!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: timemeasure function give 0ms ?
Just popping in
Joined:
2007/7/30 21:55
From Sweden
Posts: 183
@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
   Report Go to top





[Advanced Search]


Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project