Posts: 544
Threads: 27
Joined: Jan 2005
Quote:By adding the xx=xx+1 in the For...Next loop, you're making it work twice as hard as the others. It's already counting, where the others aren't, ya know?
Just as I figured! Twice as hard, because the loop has to loop through two lines, instead of one, since the first line is passed through only once, the first time around. And, the results bear this out, giving 6 seconds for the two lines, and 3 seconds for one.
Of course, I used n# =10,000,000, in order to get some meaningful time.
From all the above, I see that any lines that can be deleted or compressed will have a measureable time-reduction on a very large number of iterations, which is what I think the Dr's reason for measuring loop-times was.
So, it all boils down to, "reduce the number of lines of code as much as possible. in any many-times iterative loop". Reducing the time in that manner, rather than the type of loop used, seems to be the significant conclusion, so far.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Posts: 1,774
Threads: 62
Joined: Aug 2003
Exactly. Rel and I were attemptig to make a meaningful 3D engine with QB4.5, before FreeBASIC was released. Thankfully, we didn't waste a bunch of time. Even with Assembler, QB is much too slow to produce a fast 3D engine. It's ok for models with a very low amount of vertices, but when you try to add shadow extrusion, bump mapping, etc... it's just too slow.
Posts: 544
Threads: 27
Joined: Jan 2005
wow!!! I tried my program in FB, and, even using n# = 100000000,
and, instead of using one 10-cycle loop, I tried two 100000000-cycle loops, and I was just barely getting some decimal places for the slowest-running WHILE/WEND loop!!! FB is faster then Superman!
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Posts: 421
Threads: 22
Joined: Oct 2005
Not faster than an Intrepid-class ship, though.
In the beginning, there is darkness â the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Posts: 544
Threads: 27
Joined: Jan 2005
Antoni:
After I ran my original program in FB, without modifications, and thought it was super, super, super fast, I got to thinking, "Maybe I have to dimension my variables first, otherwise, they are not recognized, and, the program executes extremely fast, jumping all the loops!" So, I modified the original program by dimensioning the variables first, and multiplying the constant, n#, by 150. That seems to be the approximate speed multiplier using FB versus QB.
These are the FB answers for version 0.14:
FOR/TO 3.132, FOR/TO+ 3.202, DO/LOOP 5.823, WHILE/WEND 5.794
Seems the FOR/TO loops ran almost at the same speed, and almos twice as fast as the other loops.
Here is my FB code:
Code: 'LoopTimeFB times various loops in FreeBasic, version 0.14
CLS
dim i as long, J as long, k as long, t as single, t0 as single, t1 as single
dim t2 as single, t3 as single, t4 as single
PRINT
A$ = "Comparison of average times in 10 loops of three loop-times in FreeBasic"
PRINT SPC(40 - LEN(A$) / 2); A$
PRINT
A$ = "Second LOOP, FOR/NEXT+, has the unnecessary line, i = i + 1"
PRINT SPC(40 - LEN(A$) / 2); A$
PRINT
PRINT " Iteration T I M E I N S E C O N D S "
PRINT " ----------------------------------------------------------"
PRINT " No. FOR/NEXT FOR/NEXT+ DO/LOOP WHILE/WEND "
PRINT " --------- ------------- ------------- ------------- -------------"
n# = 10000000*150
FOR J = 1 TO 10
LOCATE 9 + J, 6: PRINT J
'FOR/NEXT
i = 0
t0 = TIMER
FOR k = 1 TO n#
NEXT k
t = TIMER
t1 = t1 +t - t0
LOCATE 9 + J, 4 + 12 - 5: PRINT t1 / J
'FOR/NEXT+
i = 0
t0 = TIMER
FOR k = 1 TO n#
i = i + 1
NEXT k
t = TIMER
t2 = t2 + t - t0
LOCATE 9 + J, 4 + 24-2: PRINT t2 / J
'DO/LOOP
i = 0
t0 = TIMER
DO WHILE i < n#
i = i + 1
LOOP
t = TIMER
t3 = t3 + t - t0
LOCATE 9 + J, 4 + 36 + 1: PRINT t3 / J
'WHILE/WEND
i = 0
t0 = TIMER
WHILE i < n#
i = i + 1
WEND
t = TIMER
t4 = t4 + t - t0
LOCATE 9 + J, 4 + 48+4: PRINT t4 / J
NEXT J
for i = 1 to 2:i=0:next i
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
|