Speed up Matrix Addition in C#

前端 未结 15 1169
北荒
北荒 2021-02-05 22:48

I\'d like to optimize this piece of code :

public void PopulatePixelValueMatrices(GenericImage image,int Width, int Height)
{            
        for (int x = 0;         


        
15条回答
  •  一整个雨季
    2021-02-05 23:13

    I recommend that you profile this code and find out what's taking the most time.

    You may find that it's the subscripting operation, in which case you might want to change your data structures from:

    long sumOfPixelValues[n,m];
    long sumOfPixelValuesSquared[n,m];
    

    to

    struct Sums
    {
        long sumOfPixelValues;
        long sumOfPixelValuesSquared;
    }
    
    Sums sums[n,m];
    

    This would depend on what you find once you profile the code.

提交回复
热议问题