I am working on application that requires so many loops and array access to compare arrays. I implemented the same application in c++ and I noticed very big difference in performance please notice I used pointers instead of array index-based access in the c++ version. Then I tried to implement just a small part of my code in both c++ and C#. The C# code is listed below it takes av of 400 ms to execute when measured using stopwatch. Moreover when I increase the limit of the first for to say 10000 the program will never execute just like a deadlock.
int[] A = new int[10000];
int[] B = new int[10000];
Stopwatch sw = new Stopwatch();
sw.Start();
for(int i=0;i<100;i++)
for(int j=0;j<i;j++)
for (int k = 0; k < 10000; k++)
{
A[k] = k;
B[k] = A[k] + j;
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Console.ReadLine();
my question is how to improve this killing performance of arrays in c# ?
myPC is 4GB RAM core i5 2.2GHz