I was just wondering. thinBasic is really fast, but if we ever hit loops or something where we notice it to slow down... can we do something in like a compiled language to do the code to get the performance if we need it? Would this make sense? I guess I am confused with how things like that would happen?
ErosOlmi
18-07-2007, 07:05
Ken,
it makes perfect sense!.
I will reply with a simple module example. Imagine you need a function that giving a string buffer and 2 numeric values will return the left and right most part.
So for example giving LeftRight("ABCDEFGH", 2, 3) will return a string with the 2 left most bytes and the 3 right most bytes. So result will be the string "ABFGH"
Now imagine you create a script function making this simple job:
'---
' Return left and right most buffer
'---
function ScriptLeftRIght(sBuffer as string, nLeft as long, nRight as long) as string
function = left$(sBuffer, nLeft) & right$(sBuffer, nRight)
end function
Now imagine you need to call this function 100000 or more times:
DIM MaxCount AS LONG = 100000
FOR counter = 1 TO MaxCount
sResult = ScriptLeftRIght(sBuffer, 20, 20)
NEXT
What do you think will be the time to execute it? Some seconds in many computers.
Now what about if LeftRight function is a compiled function inside a personalized module? What do you think will be the time to execute it if function is a compiled function inside a module? Few millisecs.
This makes a perfect sense. Since LeftRight function is enough general to be created as module based it is worth to do it.
Please see attached files with script source code and a module example you can compile using Power Basic.
Try to execute the script and see the difference.
Modules creation is one of the most important part of thinBasic. The capacity to integrate with external dlls and to load thinBasic specific dlls, that we call modules, able to add new native keywords to thinBasic language is one of the most important aspects aof thinBasic.
Ciao
Eros