I wrote a little program to calculate the “winning” boards of the Knight’s Tour problem after my grandfather brought it up and noticed some C# array performance stats while I was at it. I ended up using lots of .Clone() operations on the arrays and just some basic index accessing.
On the first try, I wrote it with a multidimensional int[,] array and it took 48.5s to run 10M iterations. After reading that you should really flatten multidimensional arrays, and changing the code to just use int[], it only took 10.2s to run otherwise identical code. That’s pretty huge.
Out of curiosity, I switched it again to use ArrayList objects and knocked it even further down to 6.4s.
So, multidimensional arrays, slow! ArrayLists, fast! Is anything else better?