Perfomance thoughts on interception Post 3 of several

More measurements.

Now let's measure what is the cost in performance of an array access.

Test Code:

    public static void Main()
    {
        long costs=0;
        int times = 10;
        for (int i = 0; i < 10; i++)
        {
            costs += test3();
        }
        Console.WriteLine($"Average is {costs/times}");
        Console.ReadLine();
    }

  static long test3()
    {
        var list = new Class1[500];

        var accesos = new int[10000000];
        var rand = new Random();
        for (var j = 0; j < 10000000; j++)
        {
            accesos[j] = rand.Next(500);
        }
        var st = new Stopwatch();
        st.Start();
        object outVal;
        for (var j = 0; j < 10000000; j++)
        {
            var access = accesos[j];
        }
        st.Stop();
        var setupcost = st.ElapsedMilliseconds;
        Console.WriteLine("Cost of setting up randon key access in ms " + setupcost);
        st.Reset();
        st.Start();
        for (var j = 0; j < 10000000; j++)
        {
            var access = list[accesos[j]];
        }
        st.Stop();
        var cost = st.ElapsedMilliseconds;
        Console.WriteLine("Cost of list access (removing the setup cost) in ms" + (cost - setupcost));
        return cost;
    }

Debug:
Average is 63ms

Release:
Average is 7ms

NOTE: Esteban asked how much time it takes if we use a list<> instead of array
On Release 6ms
On Debug 22ms

WOW! Is it interesting. Why? ... well that is probably a good question for another post