Calculating time difference

Previous topic - Next topic

MrTAToad

What is the best way to check the difference between two GETTIMERALL values.

At the moment, I use :

QuoteABS(GETTIMERALL()-loop.currentTime)>=5000.0

but I'm not sure whether

Code (glbasic) Select
loop.currentTime=GETTIMERALL()+5000.0
IF GETTIMERALL()>=loop.currentTimer


would be better

Kitty Hello

one time stamp can't be bigger than an stamp taken before (unless it wraps around, but that's a a few days)

I always do:
Code (glbasic) Select

now% = GETTIMERALL()
  IF loop.stoptime > now
     // do something
     loop.stoptime = now + 5000
  ENDIF



Crivens

I normally do:-
Code (glbasic) Select
now=gettimerall()
while 1=1
  if gettimerall()-now>5000
    dosomething
    now=gettimerall()
  endif
wend


Works for me...

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Kitty Hello

the "cool" thing about my method is, that if you initialize the stoptime variable with 0, it will be triggered on the first run.

Crivens

True, plus you are using less calculations on the check. I like finding very slightly faster code over stuff used for years :) Similar feeling when I discovered the old A=1-A to toggle a Boolean. Brought a smile to my face that did after years of ignorance.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.