[Mono-list] Array.Copy performance

Tum tum@veridicus.com
Wed, 4 Dec 2002 02:53:32 +1300


Hi,

I was writing a program that was making heavy use of Array.Copy to copy
small amounts of data (the data consisted of 4 byte audio frames).

The MS jitter seems to inline Array.Copy (memcpy?) because it performs
over 10 times faster than Mono.

Here's some test code:

using System;

public class Test
{
	public static void Main()
	{
		int size = 4;
		byte[] src, des;
		long ticks;

		src = new byte[size];
		des = new byte[size];

		ticks = System.Environment.TickCount;

		for (int i = 0; i < 3000000; i++)
		{
			Array.Copy(src, 0, des, 0, size);
		}

		Console.WriteLine(System.Environment.TickCount - ticks);
	}
}

I'm getting about 1312ms on .NET and 18106ms on Mono.  13 times slower
:(.

I've since rewritten my code to make copies in larger chunks and the CPU
usage is now comparable to .NET.  

How hard would it be to inline Array.Copy with the current jitter
implementation [I haven't explored the code much]?


Wibble.

^Tum