routine speed question
Mohamed-
Your routine must decide to not do several things before it goes to
the decrement routine, so that will take longer than the other two
possibilities.
One way to speed things up is to move your least likely case (the
match or near match) to the bottom of your series of IFs. Better
yet, if speed is crucial, minimize the IFs and GOTOs:
loop:
if in0 = 0 then keypad
dispVal = ADdata**weighFactor + ADdata
gosub Maxdisplay
weighFactor = constant / dispVal + weighFactor
weighFactor = weighFactor - ( dispVal / constant )
if dispVal > (constant+1) OR dispVal < (constant-1) then loop
dispVal = weighFactor
goto writedata
This technique will increment or decrement weighFactor based on the
results of integer division. Ought to speed things up a lot.
Regards,
Steve
Your routine must decide to not do several things before it goes to
the decrement routine, so that will take longer than the other two
possibilities.
One way to speed things up is to move your least likely case (the
match or near match) to the bottom of your series of IFs. Better
yet, if speed is crucial, minimize the IFs and GOTOs:
loop:
if in0 = 0 then keypad
dispVal = ADdata**weighFactor + ADdata
gosub Maxdisplay
weighFactor = constant / dispVal + weighFactor
weighFactor = weighFactor - ( dispVal / constant )
if dispVal > (constant+1) OR dispVal < (constant-1) then loop
dispVal = weighFactor
goto writedata
This technique will increment or decrement weighFactor based on the
results of integer division. Ought to speed things up a lot.
Regards,
Steve
Comments
The following subroutine is to adjust the 'weighFactor' to get desired value
equal to a 'constant'.
The question is why the speed of the routine is fast with large numbers for
'constant'(e.g 30000)and very slow for small numbers like 500 ?
loop
if in0 = 0 then keypad
dispVal = ADdata**weighFactor + ADdata
gosub Maxdisplay
if dispVal < constant then increment 'reading is less than
'desired value.
if dispVal <= (constant+1) AND dispVal >= (constant-1) then done
'reading is around desired value.
if dispVal > constant then decrement 'reading is more than desired
'value.
increment
weighFactor = weighFactor + 1
goto loop
decrement
weighFactor = weighFactor - 1
goto loop
done
dispVal = weighFactor
goto writedata
Thank You
Mohamed Refky
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
It looks to me like the algorithm will _never_ converge if
constant>ADdata. Is that a possibility? The speed of convergence
will depend on how the initial guess for weighfactor is to the
correct final value.
-- regards
Tracy Allen
electronically monitored ecosystems
http://www.emesystems.com
mailto:tracy@e...
>Hello,
>The following subroutine is to adjust the 'weighFactor' to get desired value
>equal to a 'constant'.
>The question is why the speed of the routine is fast with large numbers for
>'constant'(e.g 30000)and very slow for small numbers like 500 ?
>
>
>loop
>if in0 = 0 then keypad
>dispVal = ADdata**weighFactor + ADdata
>gosub Maxdisplay
>if dispVal < constant then increment 'reading is less than
> 'desired value.
>if dispVal <= (constant+1) AND dispVal >= (constant-1) then done
> 'reading is around desired value.
>if dispVal > constant then decrement 'reading is more than desired
> 'value.
>
>increment
> weighFactor = weighFactor + 1
> goto loop
>decrement
> weighFactor = weighFactor - 1
> goto loop
>done
> dispVal = weighFactor
> goto writedata
>
>Thank You
>Mohamed Refky
> ...I tested your routine but there is no speed difference.It is
> the same,very slow with small number for 'constant',faster as
> 'constant' increases...
Then I suspect there is a fundamental problem in the math technique,
as Tracy suggested. Can you describe in functional terms what you
mean for the algorithm to accomplish, typical values involved, etc.?
Regards,
Steve
I tested your routine but there is no speed difference.It is the same,very
slow with small number for 'constant',faster as 'constant' increases.
>From: "S Parkis" <parkiss@e...>
>Reply-To: parkiss@e...
>To: "Mohamed REFKY" <refky@h...>, basicstamps@yahoogroups.com
>Subject: Re: [noparse][[/noparse]basicstamps] routine speed question
>Date: Fri, 20 Jul 2001 09:33:42 +0800
>
>Mohamed-
>
>Your routine must decide to not do several things before it goes to
>the decrement routine, so that will take longer than the other two
>possibilities.
>
>One way to speed things up is to move your least likely case (the
>match or near match) to the bottom of your series of IFs. Better
>yet, if speed is crucial, minimize the IFs and GOTOs:
>
>loop:
>if in0 = 0 then keypad
>dispVal = ADdata**weighFactor + ADdata
>gosub Maxdisplay
>weighFactor = constant / dispVal + weighFactor
>weighFactor = weighFactor - ( dispVal / constant )
>if dispVal > (constant+1) OR dispVal < (constant-1) then loop
>dispVal = weighFactor
>goto writedata
>
>This technique will increment or decrement weighFactor based on the
>results of integer division. Ought to speed things up a lot.
>
>Regards,
>
>Steve
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp