Now I am using valgrind/callgrind to meaure and compare different algorithm implementations. Suppose there are two implementations for an algorithm, and the processing chains are as follows:
void main()
{
//Procedure 1
fun1();
//Procedure 2
fun2();
//Procedure 3
Algorithm_imp_1(); //Algorithm_imp_2();
//Procedure 4
fun4();
}
The difference between these two implementations lies in the third procedure, where two different algorithm implementations are performed. In order to see which implementation is better, I am now using valgrind/callgrind with the help of kachegrind.
As far as I can image, if Algorithm_imp_1()
is more efficient than Algorithm_imp_2()
, its two indicators: one is the absolute time that have been used for running the program , and the other is the percentage of the time the third procedure takes, should be smaller. However, what I have obtained with valgrind are very confusing:
Method 1 whole procedure: overall circle 106858896849
Algorithm_imp_1(): circle 2971828457(3.03%)
Method 2 whole procedure: overall circle 137889090577
Algorithm_imp_2(): circle 351826053(0.26%)
Since the whole procedure for the both methods are the same expect the third part, if the consumed time percentage of the third part is small, we can expect the overall time for running the program should also be small. However, what we observed above are contradictory. I was wondering what's wrong with my analysis. Thanks!