Modifying for loop to make it faster

Hello,

I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it helped upto few msec. Any further suggestions would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    int rows = signal.size();
    int cols = signal[0].size();
    int cols_lp1 =(int) ceil( (double) cols / 2);
    vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1));
	vector<double> temp_row;

	temp_row.reserve(512);
    for (int i =0; i < rows; i++) {
                //vector<double> temp_row;
                for (int j=0;j < cols;j++) {
                        double temp = signal[i][j];
                        temp_row.push_back(temp);
					   }
                        vector<double> oup;
                        branch_lp_dn(name,temp_row,oup);
                        temp_row.clear();

                        for (int j=0;j < (int) oup.size();j++) {
                        lp_dn1[i][j] = oup[j];
                        }
        }
Using a profiler would probably help the most. You could also store items by reference or pointer instead of by copy (though if by reference you'd need a reference wrapper).
Why is temp_row a vector, you only seem to be using a single element?

What is happening in branch_lp_dn()? How is this function defined and implemented.

Is there a way to cut down on the time using something else rather than push_back?
You could try emplace_back though doubt it will increase speed by much if any.
As I alluded to earlier temp_row doesn't seem to need to be a vector, a single floating point number should be all that is needed for that variable. However I have no idea what you're doing with the vector oup. This is probably a bigger bottle neck than temp_row, but without seeing the code for branch_lb_dn() I'm only guessing.

Topic archived. No new replies allowed.