Greetings,
I am a Physics graduate student working on a Monte Carlo simulation I wrote in C++. I've reached the point where my major concern is how fast the program runs since I need to do lots of data averaging to get clean results. I'm trying to optimize for speed and have a couple of specific questions. When I began writing the simulation I had more experience with Fortran than C++, and my code is likely somewhat oddly structured for an object oriented language.
My major question is if it makes a significant performance difference to make a function a member of a class rather than pass the class object to the function by pointer. My program is currently structured such that I have 3 classes that divide up different types of data, and I pass one or more of these class objects to global functions by pointer. The functions do work on the data. These functions perform the major work of the program and are called millions of times.
I've been considering reworking the whole thing, perhaps lumping all of the data structures into one class, and making all the functions member functions. This would be worth the effort if I gained a 10% performance increase, probably not worth it for a 1% increase.
Other than that I have heard that references can be better optimized by the compiler than pointers, and that arrays with dimensions that are a power of 2 can be manipulated more quickly. If anyone has any advice regarding these it would be appreciated.
I know which functions are slow due to their calculation burden, and it is possible no structural changes can significantly speed things up, but if anyone has any advice it would be appreciated.
Thanks.