Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

It is said that we should create functions that execute a specific action.
My question is that does doing so increase execution time?

Thanks,
Dhaval Shah
Posted

1 solution

In general yes, every time you call another method the CPU registers need to be stored and restored and parameters have to be pushed on the stack.
However, depending on various factors the compiler can optimize this away, mainly driven by the call graph of your module.
The only way to know for sure is compiling the code and then inspecting the generated IL code (e.g. using ILDASM).

But more importantly from a code maintainability perspective I would not begin with these considerations, unless a profiler is indicating that this is an actual problem.
Code structure, reuse and maintainability should drive your decisions for using methods and separating functionalities in meaningful chunks in the first place.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900