Page 1 of 1

question about execution efficiency/speed

Posted: Wed Mar 26, 2014 12:07 am
by DasTech
Hello all,
I hope I can word this well enough... Is there an appreciable difference in the speed of execution if you include and action in an object versus calling another object?

Would this take longer to execute

Code: Select all

 
on chatMessage s,data
  ...
  ReplytoClient "1001"
  ...
end chatMessage

on ReplytoClient message
   -- send the data contained in the message variable to the client
   write message to socket s with message "callbackIgniteSocket"
end ReplytoClient

Than this(omitting the ReplytoClient call)

Code: Select all

on chatMessage s,data
...
  write "1001" to socket s with message "callbackIgniteSocket"
...
end chatMessage
or not a noticeable difference?

Re: question about execution efficiency/speed

Posted: Wed Mar 26, 2014 1:13 am
by bn
Hi Das,

In fact there is a very small overhead in calling commands or functions. But you have to do it 100.000 times to see a noticeable difference in the range of a couple milliseconds.
I would modularize code as you do if that is helping you to keep it clean and maintainable.

If you are concerned about the overhead you could use "private", this again will reduce a couple of nanoseconds from the overhead. See the dictionary for private.

I usually use inline code only if I want to squeeze out the last bit of speed, like processing imageData or very long lists.

here is a short test that should give you and idea

Code: Select all

on mouseUp
   put the milliseconds into t
   speedTest1
   put the milliseconds - t into time1
   put the milliseconds into t
   speedTest2 1
   put the milliseconds - t into time2
   put time1 && time2
   
end mouseUp

on speedTest1
   repeat 100000
      add 1 to x
   end repeat
end speedTest1

on speedTest2 pNumber
   put pNumber into temp
   repeat 100000
      put addition(temp) into temp
   end repeat
end speedTest2

 function addition pNumber
   add 1 to pNumber
   return pNumber
end addition

--private function addition pNumber
--   add 1 to pNumber
--   return pNumber
--end addition

--private function addition @pNumber
--   add 1 to pNumber
--   return pNumber
--end addition
the blocked parts are variations of the function. Unblock to see effect, don't forget to block the ones you don't want to test.
the @ sign means the parameter is passed as reference to the variable and not a new variable -> see @ in the dictionary.
The results will show up in the message box.

I hope this helps a bit.

Kind regards
Bernd

Re: question about execution efficiency/speed

Posted: Wed Mar 26, 2014 4:43 pm
by DasTech
Thanks for the explanation and the code! I will try that out.