Restored from previous forum. Originally posted by tinman.
Originally posted by lordperrin
It seems that Purebasic uses a highly optimized compiler. In fact it optimizes the code to the extent that the program posted here on the board never runs the loop with 100000 iterations at all.
for x=1 to 100000
y=y+1
next x
will be compiled as just x=100000
I really doubt that, unless it compiles to "x=100000 : y=100000". Attached is some code that takes 0.77 seconds to run on my Duron 750. If it were to compile to "x=100000" then there is no way it would take that long (and it takes different times if you change the loop counter, so that shows your theory to be completely wrong).
Code: Select all
StartTime.l=StartProcessTimer_()for x.l=1 to 100000000
y.l=y+1
next x
Elapsed$=GetProcessTime$(StartTime)
MessageRequester("Bench result", "Took "+Elapsed$+" and y="+Str(y)+" loops", #PB_MessageRequester_OK)
End
if you put print "hello" in the loop instead the outcome of the speed test is a very different one. With 1000 iterations I found this:
IBasic produces an exe with the size of 389(!) kb and runs in 631 ms.
PureBasic produces an exe with the size of 8 kb and runs in 1893(!) ms
So I guess when it comes to size PB rules. When it comes to speed, well it all depends on the program.
It also depends on some other things. You did remember to turn off the PB debugger when you ran it? Did you time the entire program or did you time the inner loop? Was your PB program outputting to the console (like my code below) which is quite slow (compared to e.g. writing to a file and even worse if you are moving the mouse while the console is active)?
The code here takes 5.28 seconds to run on my Duron750.
Code: Select all
If OpenConsole()
StartTime.l=StartProcessTimer_()
for x.l=1 to 1000
y=y+1
PrintN("hello")
next x
Elapsed$=GetProcessTime$(StartTime)
MessageRequester("Bench result", "Took "+Elapsed$, #PB_MessageRequester_OK)
CloseConsole()
EndIf
End
Update: Well I won't even bother timing either tests in IBasic because the first one (with y=y+1 in the loop) is a lot slower than PB. However, the one that prints hello is visibly faster in IBasic.
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)