Is there a significant performance hit if I keep adding member functions to a class? When I use the class, I may only use a couple of the member functions together at once so I could in theory split the single class into a number of smaller classes with fewer member functions. Do I take a big performance hit by cramming a lot of functions into the same class?
Share
No, it doesn’t matter.
But presence of lot of public` api indicates that you should make sure you are following the Single responsibility principle if you are trying to have a good design.
If you design adheres to that, then its all good and cramming a lot of functions to the class is not going to do any bad in terms of performance.
Some people might argue about performance hit if those functions are
virtualhowever as long the purpose of those functions is to be overidden in the derived class then you should make themvirtual, that is unless those functions are not being madevirtualjust for the sake of flexibility but on basis of a well thought design then go ahead and make themvirtual.Performance hits shouldn’t be a concern its the price you pay for a functionality you want to have just that.
Also, Only profiling can actually give you accurate indications about performance bottle necks without it, what you get is speculations or guesses on the basis of experience which always might not be truly indicative.