I am writing a code and I came across a situation where I would like to test two different methods of doing something and time each so I can make sure I am using the most efficient of the two. I have seen folks post timing information on various questions/answers around here but I could not find any questions or answers related to how to gather and evaluate that data. My questions has 3 parts and I will use this example to explain :
I have written a function that evaluates a mathematical expression and I am storing the results in an Eigen matrix. The matrix is completely symmetric so I want to determine if it is faster to compute the all of the off diagonal elements twice like this.
//Method A
for( int i=0; i < max; i++){
for(int j= 0; j < max; j++){
storage_matrix(i,j)=my_function(i,j);
}
}
Or should I copy the off diagonal elements after I only compute them one essentially making the second loop restricted by the first like this.
//Method B
for( int i=0; i < max; i++){
for(int j= 0; j < i; j++){
storage_matrix(i,j)=my_function(i,j);
storage_matrix(j,i)=storage_matrix(i,j);
}
}
Now this is a very simple example but I would like to learn how to evaluate these types of things so I think a simple example is best. I have an idea about which is faster, but I want to know. I want to look at some numbers and say, "yes this is faster", or perhaps even, "wow look it doesn't make that much of a difference."
Now my 3-part question:
How do I look at timing information in general for code?
Should there be a difference in which is faster depending on the size of max? (ie. should I test withe large and small values for max)
Do I just want to know which does the job in less time or are there other considerations that need to be made when I look into issues Like this?
NB: I am using C++