[Mono-list] Array benchmark

Sijmen Mulder Sijmen Mulder <sjmulder@gmail.com>
Sat, 9 Oct 2004 13:04:00 +0200


------=_Part_943_154902.1097319840953
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

> Forgot the attachment?

Here they are. The exported txt file doesn't look to good, though, but
it'll be clear.

-- 

 'May the Lord bless you and protect you. May the Lord smile on you
and be gracious to you. May the Lord show you his favor and give you
his peace.'
 'De Heer zegent je, en Hij bewaart je. De Heer kijkt met liefde naar
je, en Hij is je genadig. De Heer bedenkt het goede voor je, en geeft
je vrede.'

Sijmen Mulder

------=_Part_943_154902.1097319840953
Content-Type: text/plain; name="Program.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="Program.cs"

using System;
using Microsoft.Win32;

namespace ArrayBench
{
=09delegate float TestMethod();
=09
=09class Program1000
=09{
=09=09const int size =3D 1000;
=09=09long endTime;

=09=09TestMethod[] tests;

=09=09void start()
=09=09{
=09=09=09endTime =3D DateTime.Now.Ticks+100000000;
=09=09}

=09=09bool stop()
=09=09{
=09=09=09return DateTime.Now.Ticks>=3DendTime;
=09=09}

=09=09float linear()
=09=09{
=09=09=09int[] array =3D new int[size*size];
=09=09=09int   count =3D 0;
=09=09=09int   temp;

=09=09=09start();
=09=09=09while(!stop())
=09=09=09{
=09=09=09=09count++;
=09=09=09=09for(int y=3D0; y<size; y++)
=09=09=09=09=09for(int x=3D0; x<size; x++)
=09=09=09=09=09=09temp =3D array[y*size+x];=09=09=09=09=09=09
=09=09=09}

=09=09=09return count;
=09=09}

=09=09float linmatrix()
=09=09{
=09=09=09int[,] array =3D new int[size,size];
=09=09=09int    count =3D 0;
=09=09=09int    temp;

=09=09=09start();
=09=09=09while(!stop())
=09=09=09{
=09=09=09=09count++;
=09=09=09=09for(int y=3D0; y<size; y++)
=09=09=09=09=09for(int x=3D0; x<size; x++)
=09=09=09=09=09=09temp =3D array[x,y];=09=09=09=09=09=09
=09=09=09}

=09=09=09return count;
=09=09}

=09=09float matrix()
=09=09{
=09=09=09int[][] array =3D new int[size][];
=09=09=09int     count =3D 0;
=09=09=09int     temp;

=09=09=09for(int i=3D0; i<size; i++)
=09=09=09=09array[i] =3D new int[size];

=09=09=09start();
=09=09=09while(!stop())
=09=09=09{
=09=09=09=09count++;
=09=09=09=09for(int y=3D0; y<size; y++)
=09=09=09=09=09for(int x=3D0; x<size; x++)
=09=09=09=09=09=09temp =3D array[x][y];=09=09=09=09=09=09
=09=09=09}

=09=09=09return count;
=09=09}

=09=09public Program1000()
=09=09{
=09=09=09tests =3D new TestMethod[]
=09=09=09=09{
=09=09=09=09=09new TestMethod(linear),
=09=09=09=09=09new TestMethod(linmatrix),
=09=09=09=09=09new TestMethod(matrix)
=09=09=09=09};
=09=09}

=09=09public void Run()
=09=09{
=09=09=09RegistryKey key =3D Registry.LocalMachine.OpenSubKey(
=09=09=09=09"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
=09=09=09string name  =3D (string)key.GetValue("Identifier");
=09=09=09int    speed =3D (int)key.GetValue("~MHz");

=09=09=09Console.WriteLine("{0} at {1} MHz", name, speed);
=09=09=09Console.WriteLine();

=09=09=09Console.WriteLine("Testing {0}*{0}", size);
=09=09=09foreach(TestMethod test in tests)
=09=09=09{
=09=09=09=09Console.Write("Running {0}: ", test.Method.Name);
=09=09=09=09Console.WriteLine("{0}", test());
=09=09=09}
=09=09=09Console.WriteLine();
=09=09}
=09}

=09class Program1024
=09{
=09=09const int size =3D 1024;
=09=09long endTime;

=09=09TestMethod[] tests;

=09=09void start()
=09=09{
=09=09=09endTime =3D DateTime.Now.Ticks+100000000;
=09=09}

=09=09bool stop()
=09=09{
=09=09=09return DateTime.Now.Ticks>=3DendTime;
=09=09}

=09=09float linear()
=09=09{
=09=09=09int[] array =3D new int[size*size];
=09=09=09int   count =3D 0;
=09=09=09int   temp;

=09=09=09start();
=09=09=09while(!stop())
=09=09=09{
=09=09=09=09count++;
=09=09=09=09for(int y=3D0; y<size; y++)
=09=09=09=09=09for(int x=3D0; x<size; x++)
=09=09=09=09=09=09temp =3D array[y*size+x];=09=09=09=09=09=09
=09=09=09}

=09=09=09return count;
=09=09}

=09=09float linmatrix()
=09=09{
=09=09=09int[,] array =3D new int[size,size];
=09=09=09int    count =3D 0;
=09=09=09int    temp;

=09=09=09start();
=09=09=09while(!stop())
=09=09=09{
=09=09=09=09count++;
=09=09=09=09for(int y=3D0; y<size; y++)
=09=09=09=09=09for(int x=3D0; x<size; x++)
=09=09=09=09=09=09temp =3D array[x,y];=09=09=09=09=09=09
=09=09=09}

=09=09=09return count;
=09=09}

=09=09float matrix()
=09=09{
=09=09=09int[][] array =3D new int[size][];
=09=09=09int     count =3D 0;
=09=09=09int     temp;

=09=09=09for(int i=3D0; i<size; i++)
=09=09=09=09array[i] =3D new int[size];

=09=09=09start();
=09=09=09while(!stop())
=09=09=09{
=09=09=09=09count++;
=09=09=09=09for(int y=3D0; y<size; y++)
=09=09=09=09=09for(int x=3D0; x<size; x++)
=09=09=09=09=09=09temp =3D array[x][y];=09=09=09=09=09=09
=09=09=09}

=09=09=09return count;
=09=09}

=09=09public Program1024()
=09=09{
=09=09=09tests =3D new TestMethod[]
=09=09=09=09{
=09=09=09=09=09new TestMethod(linear),
=09=09=09=09=09new TestMethod(linmatrix),
=09=09=09=09=09new TestMethod(matrix)
=09=09=09=09};
=09=09}

=09=09public void Run()
=09=09{
=09=09=09RegistryKey key =3D Registry.LocalMachine.OpenSubKey(
=09=09=09=09"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
=09=09=09string name  =3D (string)key.GetValue("Identifier");
=09=09=09int    speed =3D (int)key.GetValue("~MHz");

=09=09=09Console.WriteLine("{0} at {1} MHz", name, speed);
=09=09=09Console.WriteLine();

=09=09=09Console.WriteLine("Testing {0}*{0}", size);
=09=09=09foreach(TestMethod test in tests)
=09=09=09{
=09=09=09=09Console.Write("Running {0}: ", test.Method.Name);
=09=09=09=09Console.WriteLine("{0}", test());
=09=09=09}
=09=09=09Console.WriteLine();
=09=09}

=09=09[STAThread]
=09=09static void Main(string[] args)
=09=09{
=09=09=09(new Program1000()).Run();
=09=09=09(new Program1024()).Run();

=09=09=09Console.WriteLine("Done!");
=09=09=09Console.ReadLine();
=09=09}
=09}
}

------=_Part_943_154902.1097319840953
Content-Type: text/plain; name="Results.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="Results.txt"

           Microsoft.NET        Mono Mono -O=3DAll      Fastest     =20
1000*1000                                      =20
Linear              2516        1383       11313     Mono Opt     =20
LinMatrix            552         306       11416     Mono Opt     =20
Matrix               423          49        9409     Mono Opt     =20
1024*1024                                      =20
Linear              3474        1709       10772     Mono Opt     =20
LinMatrix             75          80       11170     Mono Opt     =20
Matrix               605          44       11050     Mono Opt     =20
                                               =20
  Fastest     1024*768    1024*768    1024*768  Mono Opt @1024*768=20

------=_Part_943_154902.1097319840953--