> 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
using System;
using Microsoft.Win32;
namespace ArrayBench
{
delegate float TestMethod();
class Program1000
{
const int size = 1000;
long endTime;
TestMethod[] tests;
void start()
{
endTime = DateTime.Now.Ticks+100000000;
}
bool stop()
{
return DateTime.Now.Ticks>=endTime;
}
float linear()
{
int[] array = new int[size*size];
int count = 0;
int temp;
start();
while(!stop())
{
count++;
for(int y=0; y<size; y++)
for(int x=0; x<size; x++)
temp = array[y*size+x];
}
return count;
}
float linmatrix()
{
int[,] array = new int[size,size];
int count = 0;
int temp;
start();
while(!stop())
{
count++;
for(int y=0; y<size; y++)
for(int x=0; x<size; x++)
temp = array[x,y];
}
return count;
}
float matrix()
{
int[][] array = new int[size][];
int count = 0;
int temp;
for(int i=0; i<size; i++)
array[i] = new int[size];
start();
while(!stop())
{
count++;
for(int y=0; y<size; y++)
for(int x=0; x<size; x++)
temp = array[x][y];
}
return count;
}
public Program1000()
{
tests = new TestMethod[]
{
new TestMethod(linear),
new TestMethod(linmatrix),
new TestMethod(matrix)
};
}
public void Run()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
string name = (string)key.GetValue("Identifier");
int speed = (int)key.GetValue("~MHz");
Console.WriteLine("{0} at {1} MHz", name, speed);
Console.WriteLine();
Console.WriteLine("Testing {0}*{0}", size);
foreach(TestMethod test in tests)
{
Console.Write("Running {0}: ", test.Method.Name);
Console.WriteLine("{0}", test());
}
Console.WriteLine();
}
}
class Program1024
{
const int size = 1024;
long endTime;
TestMethod[] tests;
void start()
{
endTime = DateTime.Now.Ticks+100000000;
}
bool stop()
{
return DateTime.Now.Ticks>=endTime;
}
float linear()
{
int[] array = new int[size*size];
int count = 0;
int temp;
start();
while(!stop())
{
count++;
for(int y=0; y<size; y++)
for(int x=0; x<size; x++)
temp = array[y*size+x];
}
return count;
}
float linmatrix()
{
int[,] array = new int[size,size];
int count = 0;
int temp;
start();
while(!stop())
{
count++;
for(int y=0; y<size; y++)
for(int x=0; x<size; x++)
temp = array[x,y];
}
return count;
}
float matrix()
{
int[][] array = new int[size][];
int count = 0;
int temp;
for(int i=0; i<size; i++)
array[i] = new int[size];
start();
while(!stop())
{
count++;
for(int y=0; y<size; y++)
for(int x=0; x<size; x++)
temp = array[x][y];
}
return count;
}
public Program1024()
{
tests = new TestMethod[]
{
new TestMethod(linear),
new TestMethod(linmatrix),
new TestMethod(matrix)
};
}
public void Run()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
string name = (string)key.GetValue("Identifier");
int speed = (int)key.GetValue("~MHz");
Console.WriteLine("{0} at {1} MHz", name, speed);
Console.WriteLine();
Console.WriteLine("Testing {0}*{0}", size);
foreach(TestMethod test in tests)
{
Console.Write("Running {0}: ", test.Method.Name);
Console.WriteLine("{0}", test());
}
Console.WriteLine();
}
[STAThread]
static void Main(string[] args)
{
(new Program1000()).Run();
(new Program1024()).Run();
Console.WriteLine("Done!");
Console.ReadLine();
}
}
}
Microsoft.NET Mono Mono -O=All Fastest
1000*1000
Linear 2516 1383 11313 Mono Opt
LinMatrix 552 306 11416 Mono Opt
Matrix 423 49 9409 Mono Opt
1024*1024
Linear 3474 1709 10772 Mono Opt
LinMatrix 75 80 11170 Mono Opt
Matrix 605 44 11050 Mono Opt
Fastest 1024*768 1024*768 1024*768 Mono Opt @1024*768
