Posts: 122
Threads: 21
Joined: Dec 2002
for your information -- for loops are faster than conditional do-loops, and faster than do-loops with a counter and an IF statement within. just consider that when optimizing.
[Flexibal>
Posts: 3,368
Threads: 195
Joined: Jan 2003
We already discussed this.
You're wrong.
Quote:.978515625
1.2109375
Code:
CLS
start% = 0
end1% = 1
CONST step1% = 1
GOSUB try1
GOSUB try2
SLEEP
SYSTEM
try1:
t1# = TIMER
FOR j& = 1 TO 4000000
i% = start%
1 IF i% > end1% THEN GOTO 2
i% = i% + step1%
GOTO 1
2
NEXT j&
t2# = TIMER
PRINT t2# - t1#
RETURN
try2:
t1# = TIMER
FOR j& = 1 TO 4000000
FOR i% = start1% TO end1% STEP step1%
NEXT i%
NEXT j&
t2# = TIMER
PRINT t2# - t1#
RETURN
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 122
Threads: 21
Joined: Dec 2002
with my code, using for, i get 1.3sec; with do loop with an counter and an if i get 1.9 sec.
shush.
[Flexibal>
Posts: 3,368
Threads: 195
Joined: Jan 2003
show me your code.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 3,616
Threads: 287
Joined: Jan 2003
In assembly it takes less code to do a DO-type loop than a FOR-type loop. So what you say is illogical, Flex.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 3,368
Threads: 195
Joined: Jan 2003
DO loops (__with counters!!!__) do not take less time than FOR loops...
"do loops", that is do loops without "DO" but with GOTO and an IF, such as those in my code, are faster.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 3,616
Threads: 287
Joined: Jan 2003
Yes, GOTO loops are ways faster, as this is the assembly code for it:
label:
...code...
jmp label
And for FOR loops you need to use a bunch of registers, etc.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 3,368
Threads: 195
Joined: Jan 2003
Yes, GOTO loops are faster than FOR loops, but loops with an IF, an increment operator, and a few GOTOs that act exactly 100% like a FOR loop are more efficient, for unknown reasons.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.