Page 1 of 1
Posted: Sun Jul 21, 2002 9:47 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
Can the following code be faster if using other methods?
Code: Select all
For s1=0 To 4
For s2=0 To 4
For s3=0 To 4
For s4=0 To 4
For s5=0 To 4
For s6=0 To 4;
; do something
;
Next s6
Next s5
Next s4
Next s3
Next s2
Next s1
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Posted: Sun Jul 21, 2002 10:10 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
Can someone confirm if you leave out the 'i' of the next command the for next loop is faster?
for i= 1 to 1000
next i
;
;
for i= 1 to 1000
;faster
next
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Posted: Sun Jul 21, 2002 10:31 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> Can someone confirm if you leave out the 'i' of the next command the for next
> loop is faster?
Based on the following test, I'd say no -- it makes no difference. Try the test
as it stands, then remove the "loop" variable name after "Next" and the average
is still roughly the same.
Code: Select all
Debug "Doing 10 tests..."
For test=1 To 10
begin=GetTickCount_()
For loop=1 To 20000000 : Next loop
r=GetTickCount_()-begin : av=av+r
Debug "Result = "+Str(r)
Next
Debug "Average = "+Str(av/10)
PB - Registered PureBasic Coder
Edited by - PB on 21 July 2002 23:32:18
Posted: Sun Jul 21, 2002 10:58 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
Try this in lets say 10 nested loops and see the difference?
> Can someone confirm if you leave out the 'i' of the next command the for next
> loop is faster?
Based on the following test, I'd say no -- it makes no difference. Try the test
as it stands, then remove the "loop" variable name after "Next" and the average
is still roughly the same.
Code: Select all
Debug "Doing 10 tests..."
For test=1 To 10
begin=GetTickCount_()
For loop=1 To 20000000 : Next loop
r=GetTickCount_()-begin : av=av+r
Debug "Result = "+Str(r)
Next
Debug "Average = "+Str(av/10)
PB - Registered PureBasic Coder
Edited by - PB on 21 July 2002 23:32:18
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Posted: Mon Jul 22, 2002 7:32 am
by BackupUser
Restored from previous forum. Originally posted by fred.
Depending of the inner code, it could be optimized a lot I guess, a least by doing raw inlining (code will be bigger but faster...):
For example:
For k=0 to 4
a(k) = k
Next
Can be replaced logically by:
a(0) = 0
a(1) = 1
a(2) = 2
a(3) = 3
a(4) = 4
which will be of course faster
Fred - AlphaSND