class Program
{
static void Main(string[] args)
{
int[][] test = new int[1000][];
for (int i = 0; i < test.Length; i++) test[i] = new int[1000];
Stopwatch watch1 = new Stopwatch();
Stopwatch watch2 = new Stopwatch();
var array = test;
int temp = 0;
watch1.Start();
for (int i = 0; i < 1000; i++)
{
for (int j = 0; j < 1000; j++)
{
temp = array[i][j];
}
}
watch1.Stop();
Console.WriteLine($"첫 번째 for문 측정 시간 : {watch1.ElapsedTicks} ms");
///
var array2 = test;
int temp2 = 0;
watch2.Start();
for (int i = 0; i < 1000; i++)
{
for (int j = 0; j < 1000; j++)
{
temp2 = array2[j][i];
}
}
watch2.Stop();
Console.WriteLine($"두 번째 for문 측정 시간 : {watch2.ElapsedTicks} ms");
}
}
신기