Monday 15 April 2013

How to improve nested loop in C#? -



How to improve nested loop in C#? -

i have function calculate costmatrix code below.

public double[,] makecostmatrixclassic(list<pointd> firstseq, list<pointd> secondseq) { double[,] costmatrix = new double[firstseq.count, secondseq.count]; costmatrix[0, 0] = math.round(this.geteuclideandistance(firstseq[0], secondseq[0]), 3); // d(n,1) (int = 0; < firstseq.count; i++) { (int j = 0; j <= i; j++) { costmatrix[i, 0] += math.round(this.geteuclideandistance(firstseq[j], secondseq[0]), 3); } } // d(1,m) (int = 0; < secondseq.count; i++) { (int j = 0; j <= i; j++) { costmatrix[0, i] += math.round(this.geteuclideandistance(firstseq[0], secondseq[j]), 3); } } // d(n,m) (int = 1; < firstseq.count; i++) { (int j = 1; j < secondseq.count; j++) { double min = this.findmin(costmatrix[i - 1, j - 1], costmatrix[i - 1, j], costmatrix[i, j - 1]); costmatrix[i, j] = min + math.round(this.geteuclideandistance(firstseq[i], secondseq[j]), 3); } } homecoming costmatrix; }

for 3rd loop (n,m), how improve performance if "count" of each sequence 1 1000000 points.

c# loops

No comments:

Post a Comment