It won't be faster, because std::accumulate will iterate the vector as well... What you can do is to calculate all columns at once and store results in a temporary vector. It won't be much faster though - you have to iterate all columns in all rows ending up with a complexity of O(n x m) anyway. The only benefit you might have is proper use of cpu cache. You could try making things faster by calculating more than one cell at once (by reading/summing all columns in one machine instruction), but you can have overflows then.
Bookmarks