[Mono-list] Array benchmark

Michal Moskal malekith@pld-linux.org
Sat, 9 Oct 2004 12:53:02 +0200


On Sat, Oct 09, 2004 at 11:29:21AM +0200, Sijmen Mulder wrote:
> On a game development forum, someone asked what method of storing 2D
> arrays is faster. On .NET, there are three possibilities:
> 
> 1. [y*width+x]
> 2. [x,y]
> 3. [x][y]
> 
> I was wondering too, so I wrote a benchmarker. I attached the source
> and the results (as pdf). The results are remarkable!

Forgot the attachment?

> With all methods with all resolutions, Mono -is- slowest. Until..
> maximum optimalization is used. Then the Mono results are about 5
> times as good as with Microsoft.NET. Another weird thing is that
> normally, method 1 is way faster, but when Mono is used with maximum
> optimalization, method 2 is faster. And when the version with a
> resolution of a power of two is ran, both method 2 and 3 are faster.
> Just take a look at the pdf :)

Even without the attachment -- array bounds checks. In the first case
you need one check and in the second case you need two. But when array
bounds checks are removed (with -O=all), the second version can use some
internal magic to get it done faster.

Bear in mind that it may not be possible to always remove array bounds
checks.

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: ::: Logic is a nice contrast to the Real World. :: UL++++$ C++ E--- a?