[Mono-dev] C# unsafe code performance

Rusmin Susanto rusminsusanto at yahoo.com
Tue Jun 20 03:54:49 EDT 2006


Hello.
  I know that unsafe code (especially pointer arithmetic feature) can improve performance. If I have arrays
   
   double[] a1 = new double[100];
 double[] a2 = new double[100];
 double[] a3 = new double[100];
 double[] a4 = new double[100];
 double[] a5 = new double[100];
   
  and do the following:
   
   fixed(double *d1 = a1)
 fixed(double *d2 = a2)
 fixed(double *d3 = a3)
 fixed(double *d4 = a4)
 fixed(double *d5 = a5)
 for(int i = 0; i < 100; i++)
  *(d1 + i) = *(d2 + i) + *(d3 + i) + *(d4 + i) +*(d5 + i);
  
we will get a significant performance gain compared to normal array access using []
   
  However, the performance is still nowhere near gcc. C# + unsafe is a lot slower (around 60-70% slower) than gcc. The gcc code looks like this:
  
 for(int i = 0; i < 100; i++)
  *(d1 + i) = *(d2 + i) + *(d3 + i) + *(d4 + i) +*(d5 + i);
   
  where d1, d2, etc. are arrays of double.
  
I execute each code (the C# version and gcc version) 500,000 times and measure the execution time. gcc just beats C# by miles.
  My question is:
   
  Is there any way we can make the C# performance closer to gcc (eg. 5-10% slower)?
   
  Thanks for your response.
   
  
Rusmin

 		
---------------------------------
Yahoo! Groups gets better. Check out the new email design. Plus there’s much more to come.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060620/8301ad76/attachment.html 


More information about the Mono-devel-list mailing list