AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Processing performance

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Processing performance

Postby piter » Wed Feb 25, 2009 3:03 pm

Hi,

I'm playing with video processing and I need good performance. I 'made' simple 'grayscale' class that make colorful frame into grayscaled. In most this class is a copy of AForge.Imaging.Filters.Grayscale BUT:

- there is less method's calls
- there is less if statements
- method don't have to create a grayscaled bitmap but get it as an argument

Theoretically my class (Apply method) should work a very little bit faster than AForge.Imaging.Filters.Grayscale.Apply().
BUT result is opposite... My method is about 10-16% slower than original method of AForge.Imaging.Filters.Grayscale class. I think its a big difference in processing.

Only one bigger difference is that original app uses compiled DLL (AForge.Imaging.dll) and test app uses simply grayscale.cs.

Can anyone explain me why it works slower?
piter
 
Posts: 3
Joined: Sun Feb 22, 2009 8:05 pm

Re: Processing performance

Postby andrew.kirillov » Wed Feb 25, 2009 5:21 pm

Hello,

piter wrote:- there is less method's calls
- there is less if statements

Well, this is actually not the right area for optimizations in this particular case, since it takes almost nothing. I am not really sure about which IF statements exactly you are talking about, but current version of Grayscale filter has one if-statement in the main processing method. So, if you have less, then your filter must be quite specific and usable only for certain image formats.

piter wrote:- method don't have to create a grayscaled bitmap but get it as an argument

The 2.0 version also provides (will provide) this capability.

But, all these optimizations are just preparing for the main work. The main work is done in for-loops, which do processing of all pixels. So, you may optimize a lot outside of these loops, but if you make anything wrong inside loops, then you will get nothing, but bad result only.

If you really want to find a bottleneck of an algorithm and optimize it, try profiler - it will point you in the right direction.

piter wrote:Can anyone explain me why it works slower?

It is really hard to do without source code ...
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to AForge.NET Framework