Let's say I have a C++ code intended for an embedded application. The code contains bunch of virtual method calls (please don't speculate whether it is correct or not). I would like to know the time overhead related to the virtual methods calling. The reason why I am interested in that is because the virtual methods are called also from an interrupt service routine which is invoked with 50 microseconds period and at the time being the program execution consumes 24 microseconds. I would like to know whether I can save some significant amount of time in case I won't use the virtual methods.
My first idea how to do that was to add some code which will activate some gpio pin before calling one selected virtual method and then deactive the gpio pin immediately after entering the selected virtual method. Then I can measure duration of the pulse occuring at the gpio pin via oscilloscope. That time should correspond to the virtual method related time overhead. The time measurement is coupled with only one virtual method and I am not sure whether I can say that the time overhead will be equal for all of the virtual methods.
Does anybody know any better approach for measuring the time overhead related to the virtual methods call in embedded environment? Thanks in advance for any suggestions.