home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
STOSSER
/
STOSSE07.MSA
/
A
/
12.PNE
< prev
next >
Wrap
Text File
|
1987-04-22
|
3KB
|
109 lines
Understanding STOS Basic
************************
Copied from the STOS Magazine, issue 8, August 1991.
Thanks to the kind permission of Dion Guy, who retains the copyright.
This month we discuss speeding up your programs
***********************************************
If you are writing certain kinds of programs you will need every bit of
speed you can get. If you go the right way about things you can get a
considerable speed increase in areas of your programs. This month we
discuss various commands and how quickly they execute. We also offer
advice on how to improve the speed of your programs.
In STOS there are several different ways to do a loop. There are the
commands:-
For...Next, Repeat...Until and While...Wend
But which of these commands is fastest while performing a loop? Here are
a few tests to find out:
10 timer=0
20 for x=0 to 10000
30 next x
40 print timer
When you run this you should get a value of about 39. Try this
10 timer=0
20 repeat
30 inc x
40 until x=10000
50 print timer
This should produce a value of around 147. Finally-
10 timer=0
20 while x<10000
30 inc x
40 wend
50 print timer
This should give you a value around 150.
Note that the Repeat...Until and While...Wend commands take a lot longer
than the For...Next loop.
The reason for this is that the Repeat... Until and While...Wend loops
each had an extra command to deal with. This was "inc X". The For...Next
loop automatically incremented the variable X but the other two loops had
to do it manually, using an extra command.
Of course, Repeat...Until and While...Wend can do things that For...Next
would find difficult (or even impossible) to do, but in this instance
For...Next was much faster.
The For...Next loop can be improved upon even more though. Try this
program:
10 timer=0
20 for x=0 to 10000 : next x
30 print timer
This will give you a value of around 34 where as the previous For...Next
loop took 39 50ths of a second. The reason for this is that STOS has one
less line to deal with, and can therefore run the program a bit faster.
Let us move off loops and onto some other commands. Try this program:
10 timer=0
20 for A=0 to 10000
30 z=z+1
40 next A
50 print timer
This will give a value of about 157. Now try altering line 30 to:
30 inc z
When you run it now it will only be about 74! That is some speed
increase! The simple reason for this is that STOS can perform an INc or
DEC instruction much faster than a var=var+1 or var=var-1 (var means
variable). Obviously you could improve the speed even more if you put all
the commands on one line as explained above.
That concludes our speed tests for now!