Hi,
I am using gprof and find that these operations in another loop takes up most of the time:
Code:
... //_xi is precomputed 
for(each content1) for(each cont2){ //pseudo code, where content1 and content2 are both 1D int arrays of size width * height with each element taking value from 0 to 255.
    for(k = 0; k < width * height ; k++) { //19.39% time. where width and height are both int
      if(content1[k] == 0) l += _xi[content2[k]]; // 69.89% time, where  _xi is a 1D double array of size 256
    }
}
I guess the line taking 19.39% time probably could be improved by precompute width and height and store into a new variable and use it as the upper limit on k.
As to the next line taking 69.89% time, is the checking "if(content1[k] == 0)" or addition " l += _xi[content2[k]];" or both takes more time?
How can I improve the time performance in this code snippet? Thanks in advance!