Page 1 of 1

Timing Loop Variations

Posted: Tue Aug 27, 2019 10:17 pm
by olzeke51
FWIW-
there are variations in the results of timing loops
WHILE..LOOP are faster than FOR..NEXT; as Bruce states
'
while working on a Multi-Task scenario - I wanted to
eliminate the WAIT() and WAITMICRO() statements; so
I decided to use a timing loop that just increments
a value [for 6 millisecs]. I preceded the loop and the
exit with a "variable = TIMER", subtracted them, and printed it.
here are some results using 5 different 'conditionals'
1) dim'ed variable, 2) CONST, 3) debugin variable,
4) specifically defined, and 5) an Array(3) variable
.
timing-variations.jpg
timing-variations.jpg (51.6 KiB) Viewed 29471 times

Re: Timing Loop Variations

Posted: Tue Aug 27, 2019 10:19 pm
by olzeke51
here are screen capture of the program listing and its result inBT
This is for the WHILE..LOOP conditionals

Re: Timing Loop Variations

Posted: Tue Aug 27, 2019 10:20 pm
by olzeke51
two more for WHILE..LOOP

Re: Timing Loop Variations

Posted: Tue Aug 27, 2019 10:21 pm
by olzeke51
these are for the FOR..NEXT loop

Re: Timing Loop Variations

Posted: Tue Aug 27, 2019 10:22 pm
by olzeke51
the rest of the FOR..NEXT loops

Re: Timing Loop Variations - DO..UNTIL

Posted: Wed Aug 28, 2019 6:28 pm
by olzeke51
I thought of another loop method/conditional
using the DO...UNTIL command - faster results
'
delay-do-until.jpg
delay-do-until.jpg (162.09 KiB) Viewed 29460 times

Re: Timing Loop Variations

Posted: Thu Aug 29, 2019 4:20 pm
by basicchip

Code: Select all

while x
x=x-1
loop
is the fastest (an IF test and EXIT lengthens the loop.

There will also be variations depending on the size of the constant. ARM assembly allows 8 bit values to be loaded in one instruction, some constants can be done by combining shifted constants. For longer one a PC relative load is used, and depending on the context of your code, this can add a branch around the constant.

Variables are done using register relative load and store, so the first 32 variables will be the fastest. After that multiple instructions will be required.

Tod's EBT can be useful to display the compiled code.

Re: Timing Loop Variations

Posted: Fri Aug 30, 2019 10:13 pm
by olzeke51
Thanks for the info - I was suspicious of register/memory usage/branches that
would be needed for the different 'loops' that you would create - haven't delved
too much into the Assembler(on the ARM),,,yet.
'
I needed an 'exit' condition as I was trying to avoid WAITMICRO..WAIT...I was
suspicious that it effect the 'MultiTask.bas' program that I was using.
I added a 5th SUB/ENDSUB and was getting strange results... the time
allotted to each task AND the early "exit" make a very BIG difference in
the program timing.
'
Might be posting some 'MutiTask' in a bit.....
Gary Olzeke51
'