how fast to 1 Billion ?

BlitzMax Forums/BlitzMax Beginners Area/how fast to 1 Billion ?

Takuan: of course that is slower, because there is much overhead. first you call a function, which creates a new local variable and then distroys it and then must return to the main program.
I wonder however how you would implement this test which actually does the same thing but requires such a function to do it's job..

local l:int

while(l<1000000000)
  l = update(l)
wend

function update(i:int)
  local j = 1
  return i + j
endfunction


that doesnt compare to the other way people tried before in this topic

however, of course we can benchmark this whole variable construction/destruction thing:


Local start:Int
Local finish:Int
Local i:Int


start = MilliSecs()
For i = 0 To 1000000000
  func_with_var
Next
finish = MilliSecs()

Print finish-start

start = MilliSecs()
For i = 0 To 1000000000
  func_without_var
Next
finish = MilliSecs()

Print finish-start

Function func_with_var()
  Local dummy = 1
EndFunction

Function func_without_var()
EndFunction



This actually gives some odd results to me, the left column is the time of calling the function with the variable, the right column is the time of calling the other (empty) function. And I'm really not mistaken... anyone can shine any light on this?

6031 - 6731
6211 - 7305
6119 - 7256
6026 - 6817
6029 - 6992

edit: maybe I misunderstood you and were you wondering how a function which creates a local variable would compare with another function which calls a global variable. Got these results:

left = local var, mid = global var, right = no var

6059 - 6856 - 6789
6614 - 6689 - 6677
6002 - 6699 - 6830
6625 - 6779 - 6736
6000 - 7277 - 6665

Local start:Int
Local finish:Int
Local i:Int

Global g:Int

For cnt = 1 To 5

start = MilliSecs()
For i = 0 To 1000000000
  func_with_l_var
Next
finish = MilliSecs()

Print finish-start

start = MilliSecs()
For i = 0 To 1000000000
  func_with_g_var
Next
finish = MilliSecs()

Print finish-start

start = MilliSecs()
For i = 0 To 1000000000
  func_without_var
Next
finish = MilliSecs()

Print finish-start

Print 
Next
End

Function func_with_l_var()
  Local dummy = 1
EndFunction

Function func_with_g_var()
  g = 1
EndFunction

Function func_without_var()
EndFunction