GLBasic forum

Main forum => GLBasic - en => Topic started by: MrTAToad on 2011-Mar-15

Title: Calculating time difference
Post by: MrTAToad on 2011-Mar-15
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
Title: Re: Calculating time difference
Post by: Kitty Hello on 2011-Mar-15
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


Title: Re: Calculating time difference
Post by: Crivens on 2011-Mar-15
I normally do:-
Code (glbasic) Select
now=gettimerall()
while 1=1
  if gettimerall()-now>5000
    dosomething
    now=gettimerall()
  endif
wend


Works for me...

Cheers
Title: Re: Calculating time difference
Post by: Kitty Hello on 2011-Mar-15
the "cool" thing about my method is, that if you initialize the stoptime variable with 0, it will be triggered on the first run.
Title: Re: Calculating time difference
Post by: Crivens on 2011-Mar-15
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