Here's that example in Visual Studio. I've compiled that with release
build. Here's SumMatrix1 and SumMatrix2, and what I'm going to do here,
I'm going to run this. And what the main function does, it uses a loop to
work with several sizes of matrices.
It's going to start with 100x100 and then multiply that to 200x200 and
so on until a certain limit is reached just to see the differences
between using SumMatrix1 and SumMatrix2.
That's only what we're doing here.
Let me run this by pressing Ctrl+F5. So here we go.
You can see here that things look rather different.
I'm initializing the matrix to sum numbers and then summing them up in
both ways. The first time doing that with a row major way, so going
through the rows in the outer loop, and then summing up the columns for
each row, and then doing that in the other way around and measuring the
time and the actual sum.
So the actual sums are the same just to prove that we're doing the same amount
of work and really summing up the elements in the matrix.
But you notice that the results are very different from one another,
which is very surprising from a computer science perspective where
this seems to be the same kind of code.
I mean, we're doing the same kind of work, why would we get different results?
So notice, the bigger the matrices, the higher the difference
between using row major and column major approaches.
You can see the last example here with 25,600x25,600 size matrix
will get a very big difference between row major,
which is very fast, and column major, which is fairly slow.
And it's very interesting to figure out why this is the case because again,
from a theoretical perspective,
this should be exactly the same, but they're not, and they're not
because aspects of the hardware of the actual processor.