Overhead cost of a function call: Recently, I would like to apply unit testing method to my R program. The first thing i need to chop every few lines of the code into functions so that I can test each of them.
A Question comes up to my mind: What is the overhead cost of a function call? To answer this question, i wrote the following :
The result suggests several things
- The overhead cost is about 0.82 second for 1,000,000 times function call.
- If we compile the function, the overhead cost is about 0.34 second for 1,000,000 times function call.
I don’t know whether it is a huge cost, but I believe the benefit of cleaner writing code with unit testing must worth more than that!