The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Analysing .NET for Performance using NPorf

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Marcus Mac Innes

Posts: 90
Nickname: macinnesm
Registered: Mar, 2004

Marcus Mac Innes is solutions architect and director of Style Design Systems Ltd
Analysing .NET for Performance using NPorf Posted: Jun 27, 2004 12:09 PM
Reply to this message Reply

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.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Marcus Mac Innes
Latest Posts From Marcus Mac Innes' Blog

Advertisement

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:

public int get_Width()
{
int num1;
int num2 = SafeNativeMethods.GdipGetImageWidth(new HandleRef(this, this.nativeImage), ref num1);
if (
num2 != 0)
{
throw SafeNativeMethods.StatusException(num2);
}
return
num1;
}

The following change was all I needed to make:

int width = bitmap.Width;
int height = bitmap.Height;
for (int y=0; y < height;y++){
  for (int x=0; x < height; x++){
    // Some work
  }
}

24% improvement!

Read: Analysing .NET for Performance using NPorf

Topic: Shocking patent Previous Topic   Next Topic Topic: Bill Gates to blog?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use