PDF Print E-mail
Written by Daniel P   
Tuesday, 09 January 2007

While looking at ways to improve the speed of mpeg decoding in C#. I made the following little experiment.

//start timing
timer1.Start();
for( k = 0; k < 100000; k++ )
for( i = 0; i < 8; i++ )
for( j = 0; j < 8; j++ )
{
if( ptr1[i*8+j] + ptr2[i*8+j] < 8 )
ptr1[i*8+j] = 0;
else
ptr2[i*8+j] = k;
}
timer1.Stop();

timer2.Start();
for( k = 0; k < 100000; k++ )
for( i = 0; i < 8; i++ )
for( j = 0; j < 8; j++ )
{
if( arr1[i,j] + arr2[i,j] < 8 )
arr1[i,j] = 0;
else
arr2[i,j] = k;
}
timer2.Stop();

Console.WriteLine("native : {0}",timer1.Duration);
Console.WriteLine("managed: {0}",timer2.Duration);

Where ptr1, ptr2 are IntPtr "pointing" to native memory and arr1 and arr2 are 2D managed arrays of integers (timer1, timer2 are just objects of a simple wrapper around QueryPerformanceCounter).

Since similar code occurs frequently in a video decoder, I was surprised to see that the native version runs 3.5 faster than the managed arrays. So I've modified the decoder in order to use "unsafe native" arrays.




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
Last Updated ( Tuesday, 13 February 2007 )
 
< Prev   Next >
Joomla Template by Joomlashack
Joomla Templates by JoomlaShack Joomla Templates by Compass Design