question about execution efficiency/speed

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
DasTech
Posts: 6
Joined: Wed Feb 19, 2014 5:23 am

question about execution efficiency/speed

Post by DasTech » Wed Mar 26, 2014 12:07 am

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?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: question about execution efficiency/speed

Post by bn » Wed Mar 26, 2014 1:13 am

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

DasTech
Posts: 6
Joined: Wed Feb 19, 2014 5:23 am

Re: question about execution efficiency/speed

Post by DasTech » Wed Mar 26, 2014 4:43 pm

Thanks for the explanation and the code! I will try that out.

Post Reply