This post originated from an RSS feed registered with .NET Buzz
by Marcus Mac Innes.
Original Post: Analysing .NET for Performance using NPorf
Feed Title: Marcus Mac Innes' Blog
Feed URL: http://www.styledesign.biz/weblogs/macinnesm/Rss.aspx
Feed Description: Issues relating to .NET, Service Oriented Architecture, SQL Server and other technologies.
Last week we were putting the finishing touches to a major enhancement of our microfiche processing tool CropIX...
Since performance is a major issue when batch processing thousands of fiche images, we wanted to do some performance analysis to catch any processing bottlenecks.
Using NProf, we ran the application (written in C#) over a batch of sample images and were amazed by the results:
It seems that for 24% of the runtime, our application was busy getting the width of a bitmap image!!! NProf reported:
int32 System.Drawing.Bitmap::get_Width() was called 323423422 times... and took 24% of the total processing time of the batch run. The main problem was the following few lines of code:
for (int y=0; y < bitmap.Height; y++){ for (int x=0; x < bitmap.Width; x++){ // Some work } }
Looking at the disassembly of the Bitmap class (thanks Paulo and Reflector...) it would appear there is an interop call on access the Width property which might explain some level of performance draw... Additionally the bitmap images themselves were relatively large and maybe the CLR was having to pull the entire class' data from the stack just to access one of its properties. Here's the code snipped from the Bitmap class: