Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FYI
#1
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>
Reply
#2
We already discussed this.

You're wrong. Smile

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.
Reply
#3
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>
Reply
#4
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.
Reply
#5
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.
Reply
#6
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.
Reply
#7
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.
Reply
#8
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)