Which is better ?
WHILE TRUE
DrawSomething()
SHOWSCREEN
WEND
WHILE TRUE
GOSUB DrawSomething
SHOWSCREEN
WEND
I'm talking about performance
After testing this in a loop of 1 000 000 iterations, GOSUB is slightly slower, about 50 ms slower on total time which gives about 1.5 % difference.
My function and sub both draws a sprite and then exits.
Internal SUB = function without params. No more
Quote from: Moru on 2009-Jul-20
My function and sub both draws a sprite and then exits.
Try your test with math instead of calls to the gpu.
Quote from: Hemlos on 2009-Jul-21
Quote from: Moru on 2009-Jul-20
My function and sub both draws a sprite and then exits.
Try your test with math instead of calls to the gpu.
Was the same result so I tried with sprites too.
Strange, there shouldnt be a performance difference, if sub is merely a function.
Out of curiosity, im going to test this also, ill be back here with the results today.
FUNCTION nothing:
ENDFUNCTION
SUB nothing2:
ENDSUB
become
DGInt nothing()
{
__PPRegisterFunction
return 0;
}
// ------------------------ //
DGInt nothing2(void){
__PPRegisterFunction
return 0;
}
So there is no difference...
Do a test, mabe my test is flawed in some way? There isn't a bit difference so is within error tollerances I guess.
Quote from: Moru on 2009-Jul-22
Do a test, mabe my test is flawed in some way?
Nah i highly doubt it. Youre usually the one to catch these subtlties in the first place, this number bloke has more time than you haha.
And ocean is probably on target with the cause.
Personally i never used the subs.
I remember when "GOSUB" was added, it was actually an idea i had a few years ago, to marry the "old" BASIC structure to "GLBasic" as an innate ability. Its really just a sentimental asthetic anymore.
"Function" is now obviously faster, and naturally, more versatile with the ability to byref and return etc.
I would definetly recommend function.