код c#:
using System;
using System.Diagnostics;
namespace ConsoleApp19 {
class Program {
struct Cell {
public string type;
public string player;
public bool isUnit;
}
public static void Main() {
const int size = 1_000;
object[,,] objs = new object[size, size, 3];
Cell[,] cells = new Cell[size, size];
Stopwatch timer = new Stopwatch();
timer.Start();
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
objs[i, j, 0] = "type";
objs[i, j, 1] = "player";
objs[i, j, 2] = false;
string type = (string)objs[i, j, 0];
string player = (string)objs[i, j, 1];
bool isUnit = (bool)objs[i, j, 2];
}
}
timer.Stop();
Console.WriteLine(timer.ElapsedMilliseconds);
timer.Reset();
timer.Start();
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
cells[i, j].type = "type";
cells[i, j].player = "player";
cells[i, j].isUnit = false;
string type = cells[i, j].type;
string player = cells[i, j].player;
bool isUnit = cells[i, j].isUnit;
}
}
timer.Stop();
Console.WriteLine(timer.ElapsedMilliseconds);
}
}
}
Вывод:
89 (3-ёх мерный массив)
18 (2-ух мерный)