Managed vs "native" arrays 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!
 
Profiling,profiling,profiling! PDF Print E-mail
Written by Daniel P   
Wednesday, 20 December 2006

I have mentioned that I started to write some Mpeg-1 decoding routines in C#. By now, I have an almost complete decoder written in C# from scratch (i.e. I just followed the spec. or the Standard document).

Since now I can play video segments with this code, I started measuring its performance. I knew it wasn't good but I hadn't done any profiling yet. I added some timing instructions and, my initial results, were something like: more than 11 secs for my decoder vs 0.09s for FFMpeg; or around 120 times slower. After further investigations, I found that more than 95% of the decoder execution time was spent in my "naive" implementation of the IDCT. So I've changed it to a simple but faster one (the Chen-Wang algorithm) and now the running time is within five times of FFMpeg.

I'm sure that there are plenty more opportunities for optimization in the original code, so my XMas Holidays asssignment will be to continue improving its speed. These observations certainly explain the considerable efforts done in improving the performance of this critical piece of video processing: the DCT/IDCT.




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
 
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>

Results 21 - 24 of 81
Joomla Template by Joomlashack
Joomla Templates by JoomlaShack Joomla Templates by Compass Design