Function call penalty

Discuss issues and ideas you have to configuring displays with PowerVision
mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Function call penalty

Post by mbowdich » Sat Jul 30, 2011 1:07 pm

I need to know which of the scenarios will take the larger performance hit in a script. Time to complete is critical:

Common Background:

a uint8 array containing at least 8 elements
need to get the data back to parameter variables to sent via FFCAN

Scenario 1:

Use smWrite function calls to write each byte to a parameter variable -- This requires at least 16 function calls (8 smWrite and 8 smGetHandle) and data conversion to double for each. Assign a variable to each byte of the FFCAN message.

Scenario 2:

Convert and combine data to get two 4 byte numbers, convert to doubles and use only 2 smWrite function calls (and 2 smGetHandle). Assign a high and low variable to the first and last 4 bytes of the FFCAN message respectively.
dwills
Enovation Controls Development
Enovation Controls Development
Posts: 26
Joined: Fri Jul 30, 2010 8:27 am

Re: Function call penalty

Post by dwills » Thu Aug 04, 2011 8:45 am

Scenario 2 will take less time, if the data manipulation required is not too extensive. The write calls have the potential to pend on a mutex protecting the database, so the fewer of these, the less chance of pending the script and allowing it to run to completion. There would have to be substantial manipulation of the data to equal the context switch caused when the script pends.

As another note, the handles assigned to variables are static. In critical code, it is better to initialize the handle values once, and not bear the overhead of repeated calls to get the handles.
mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Re: Function call penalty

Post by mbowdich » Thu Aug 04, 2011 9:39 am

Thanks. That is also the scenario I figured would work the best.
Unfortunately, the getHandle call needs to be done more than once in this case, as I do not know what handle needs to be called at compile time. There is another function in the script that determines this durng runtime. I know I take a substantial hit for the call, but I am trying to de this as little as possible (1-2 times per call).