Liberty BASIC Community Forum
« Loop speed »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 6:06pm


Rules|Home|Help|Search|Recent Posts|Notification

Problems installing Liberty BASIC? Read the Vista/Win7 Installation FAQ
Looking for a categorized List of Bug Reports? Visit the Liberty BASIC Bug Tracker

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Loop speed  (Read 36 times)
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Loop speed
« Thread started on: Dec 21st, 2017, 3:18pm »

I'm not quite sure it's a bug but I hope Carl could have a look at this. May be something could be done compile time?

LB provides several methods to do loops.
It really makes sense if they run at about same speed, yes?

Now here results I got in LB 4.5.1
Code:
Running 7 timed tests please wait...
100000 times adding in
While... Wend time is 1375
DO WHILE/LOOP time is 1360
DO/LOOP WHILE time is 1406
DO UNTIL/LOOP time is 1625
DO/LOOP UNTIL time is 1594
GOTO [do] loop time is 1078
FOR loop time is 1000 

Basically, LOOP simulation via GOTO works on par with FOR loop
While, DO WHILE, DO/LOOP WHILE works 30% slower
DO UNTIL, DO/LOOP UNTIL works some more 30% slower
interesting but I have about same times if I change UNTIL with WHILE NOT(opposite condition)
Now, the question is - why?
May be there is some un-needed code - may be debug code - is inserted while translating LB to underlying code?

the code is here
Code:
Print "Running 7 timed tests please wait..."
n = 100000
t1 = time$("ms")
x = 0 : i = 0
while i < n
    i = i + 1
    x = x + i
wend
t2 = time$("ms")

x = 0 : i = 0
do while i < n
    i = i + 1
    x = x + i
loop
t3 = time$("ms")

x = 0 : i = 0
do
    i = i + 1
    x = x + i
loop while i < n
t4 = time$("ms")

x = 0 : i = 0
do until i > n
    i = i + 1
    x = x + i
loop
t5 = time$("ms")

x = 0 : i = 0
do
    i = i + 1
    x = x + i
loop until i > n
t6 = time$("ms")

x = 0 : i = 0
[do]
    i = i + 1
    x = x + i
    if i < n then goto [do]
t7 = time$("ms")

x = 0
for i = 0 to n
    x = x + i
next
t8 = time$("ms")


print n; " times adding in"
print "While... Wend time is ";t2-t1
print "DO WHILE/LOOP time is ";t3-t2
print "DO/LOOP WHILE time is ";t4-t3
print "DO UNTIL/LOOP time is ";t5-t4
print "DO/LOOP UNTIL time is ";t6-t5
print "GOTO [do] loop time is ";t7-t6
print "FOR loop time is ";t8-t7
 
User IP Logged

damned Dog in the Manger
cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 630
xx Re: Loop speed
« Reply #1 on: Dec 21st, 2017, 3:56pm »

GOTO For the win!! Yeah. Well, I actually always use GOTO for testing and debugging. Quite useful.
User IP Logged

cundo
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Liberty BASIC Community Wiki
Wikispaces
Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls