internal class Program
{
static void Main(string[] args)
{
int k = 10_000;
Console.WriteLine("Hello, World!");
Stopwatch s = new Stopwatch();
int[][] a1 = new int[k][];
int[,] a2 = new int[k, k];
int[] a3 = new int[k * k];
for (int i = 0; i < k; i++)
{
a1[i]=new int[k];
for (int j = 0; j < k; j++)
{
a1[i][j] = Random.Shared.Next(10000);
a2[i,j] = a1[i][j];
a3[j+k*i] = a1[i][j];
}
}
int n = 20;
long sum = 0;
s.Start();
for (int l = 0; l < n; l++)
{
for (int i = 0; i < k; i++)
{
for (int j = 0; j < k; j++)
{
sum+=a1[i][j] ;
}
}
}
s.Stop();
Console.WriteLine(" sum:" + sum + ", "+s.ElapsedMilliseconds);
s.Restart();
sum = 0;
for (int l = 0; l < n; l++)
{
for (int i = 0; i < k; i++)
{
for (int j = 0; j < k; j++)
{
sum += a2[i, j] ;
}
}
}
s.Stop();
Console.WriteLine(" sum:" + sum + ", " + s.ElapsedMilliseconds);
s.Restart();
sum = 0;
for (int l = 0; l < n; l++)
{
for (int i = 0; i < k; i++)
{
int _i = i * k;
for (int j = 0; j < k; j++)
{
sum += a3[j +_i] ;
}
}
}
s.Stop();
Console.WriteLine(" sum:" + sum + ", " + s.ElapsedMilliseconds);
}
}
// [][] 4865
//[,] 5192
//[] 4852
// [][] 4865 // [,] 5192 // [] 4852