Improving performance using callgrind tool of valgrind