Timing Loop Variations

Questions about the BASICtools and MakeItC
Post Reply
olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Timing Loop Variations

Post 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 15941 times
Attachments
loop-variations.xls
(6 KiB) Downloaded 639 times
loop-variations.ods
(10.72 KiB) Downloaded 670 times



olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Timing Loop Variations

Post by olzeke51 »

here are screen capture of the program listing and its result inBT
This is for the WHILE..LOOP conditionals
Attachments
delay-debugin.jpg
delay-debugin.jpg (143.75 KiB) Viewed 15940 times
delay-CONST.jpg
delay-CONST.jpg (122.83 KiB) Viewed 15940 times
delay-array.jpg
delay-array.jpg (124.83 KiB) Viewed 15940 times

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Timing Loop Variations

Post by olzeke51 »

two more for WHILE..LOOP
Attachments
delay-variable.jpg
delay-variable.jpg (133.48 KiB) Viewed 15940 times
delay-specific.jpg
delay-specific.jpg (140.96 KiB) Viewed 15940 times

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Timing Loop Variations

Post by olzeke51 »

these are for the FOR..NEXT loop
Attachments
delay-for-debugin.jpg
delay-for-debugin.jpg (114.17 KiB) Viewed 15940 times
delay-for-CONST.jpg
delay-for-CONST.jpg (110.61 KiB) Viewed 15940 times
delay-for-array.jpg
delay-for-array.jpg (121.96 KiB) Viewed 15940 times

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Timing Loop Variations

Post by olzeke51 »

the rest of the FOR..NEXT loops
Attachments
delay-for-variable.jpg
delay-for-variable.jpg (108.53 KiB) Viewed 15940 times

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Timing Loop Variations - DO..UNTIL

Post 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 15930 times

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Timing Loop Variations

Post 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.

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Timing Loop Variations

Post 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
'

Post Reply