Speed up Matrix Addition in C#

前端 未结 15 1390
北荒
北荒 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:08

    matrix's addition complexity is O(n^2), in number of additions.

    However, since there are no intermediate results, you can parallelize the additions using threads:

    1. it easy to proof that the resulting algorithm will be lock-free
    2. you can tune the optimal number of threads to use

提交回复
热议问题