Tag Archives: Xbox 360

There are many ways to create 2D arrays in C# so I decided to take a look at 4 different methods and see which one was the fastest.

The 4 types that were chosen:

  • List of lists(List< List < > >)
  • Jagged arrays ([][])
  • Multidimensional arrays ([,])
  • 1D array using maths to find the place ((y * size) + x).

1000 x 1000 sized arrays were created and tested, these tests included Creation, Filling, finding 1 value (at position 500×500) and iterating across the whole array, time is in milliseconds.

 

Results

Windows7
List of Lists
   Create: 0    Build: 29.0016
   Find 1: 0   Iterate: 15.0009
Multi Dimensional
    Create: 0    Build: 12.0007
    Find 1: 1.0001    Iterate: 11.0006
Jagged
    Create: 0    Build: 8.0004
    Find 1: 0    Iterate: 6.0004
1D Array
    Create: 0    Build: 8.0004
    Find 1: 0    Iterate: 6.0004

WP7
List of Lists
   Create: 64    Build: 261
   Find 1: 1   Iterate: 142
Multi Dimensional
    Create: 4    Build: 120
    Find 1: 0    Iterate: 120
Jagged
    Create: 0    Build: 64
    Find 1: 0    Iterate: 46
1D Array
    Create: 0    Build: 64
    Find 1: 0    Iterate: 46

XBOX 360
List of Lists
   Create: 5    Build: 185
   Find 1: 0   Iterate: 139
Multi Dimensional
    Create: 1    Build: 120
    Find 1: 0    Iterate: 136
Jagged
    Create: 1    Build: 64
    Find 1: 0    Iterate: 62
1D Array
    Create: 1    Build: 64
    Find 1: 0    Iterate: 62

 

From the numbers is looks like C# internally works a Jagged array as a 1D array and does that math for us and so from a speed and easy of use point of view it seems Jagged arrays win out.

 

Huge thanks to MadNinjas of #XNA (irc.efnet.net) for running the code on the other platforms!

[edit]
It seems I had mixed up the multi dimensional and jagged arrays in my code so my numbers were wrong, this is now fixed.