CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Measure the overhead of function call

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

Measure the overhead of function call
PostPosted: Wed Oct 19, 2005 10:36 am     Reply with quote

All,

Hi,

I am not a mature programmer in embedded systems so I come up with these questions

Q:
1. How heavy can the overhead of a function call be?
2. Does the overhead vary according to the content and size of the function?
3. Is it possible, in real time systems, function overhead cause significant delay?
4. Are there ways around function overhead?


I come up with these questions because i am trying to modulize my code.
For example, I list some sections of code in a sequential order within main() and now thinking about moving these individual portions of code away into individual functions and then list only the function names in main().
Well, this actually is the way I always adopt but just somehow didn't ever think about the overhead of function call.

Can somebody figure out the puzzle here for me plz?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 19, 2005 10:47 am     Reply with quote

Quote:
1. How heavy can the overhead of a function call be?


Depends on how many parameters are passed and how many variables are used in the function. Similarly if you call by value as opposed to call by reference.

Quote:

2. Does the overhead vary according to the content and size of the function?


see above

Quote:

3. Is it possible, in real time systems, function overhead cause significant delay?

This depends on what you means by significant delay (how long is a piece of string). It takes CPU cycles to copy register values plus the call and return overhead etc.

Quote:

4. Are there ways around function overhead?

You can code in-line as you mentioned to avoid calling overhead but it is likely the comiler will introduce calls anyway as part of its optimization.

The best thing to do is compile some code and look at the code produced in the .lst file
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Measure the overhead of function call
PostPosted: Wed Oct 19, 2005 11:57 am     Reply with quote

ye wrote:
All,

Hi,

I am not a mature programmer in embedded systems so I come up with these questions

Q:
1. How heavy can the overhead of a function call be?
2. Does the overhead vary according to the content and size of the function?
3. Is it possible, in real time systems, function overhead cause significant delay?
4. Are there ways around function overhead?


I come up with these questions because i am trying to modulize my code.
For example, I list some sections of code in a sequential order within main() and now thinking about moving these individual portions of code away into individual functions and then list only the function names in main().
Well, this actually is the way I always adopt but just somehow didn't ever think about the overhead of function call.

Can somebody figure out the puzzle here for me plz?


For a function that is #inline and has no parameters there is no overhead. If parameters are involved add the overhead of copying the variables. For a function that is #seperate add overhead for call and return.
If a function is only called once it will be assembled #inline by default with a few exceptions. If a function is called more than once it will be assembled #seperate by default. Declaring a function #inline or #seperate will override the defaults.
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 4:32 pm     Reply with quote

Neutone, asmallri, thanks a lot! Razz


All,

I still have some confusions here and may I ask some more questions

Quote:
Depends on how many parameters are passed and how many variables are used in the function

Quote:
It takes CPU cycles to copy register values plus the call and return overhead etc.


I am wondering what this claim is based? Say, how the PIC deal with parameter passings? .... You are saying 'copy register values plus the call and return overhead etc', what exactly does it mean? Are you saying, like, when function A calls function B, function A can't directly access both parameters and variables of function B. Instead, these parameters and variables are copied to some intermediate registers and then used by function A indirectly?
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 4:35 pm     Reply with quote

Neutone,

I am pretty impressed by your understanding. Wondering if you got those from programming experience or you can recommend any website that gives insightful knowledge?
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu Oct 20, 2005 7:41 am     Reply with quote

You can get a better understanding of all of this by writing some simple code that does these things and then looking at the listing file. In the listing file you can see the assembly generated for these things.

A good example would be a function called twice in a for loop that has parameters.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group