[Mono-list] Array.Copy performance

dietmar dietmar@ximian.com
03 Dec 2002 15:09:43 +0100


On Tue, 2002-12-03 at 14:53, Tum wrote:
> 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]?
> 

I will take a look at it.

- Dietmar