[Clam-devel] [PATCH] std::vector operator[] and not calling frameSize()

Pau Arumi parumi at iua.upf.edu
Thu Jun 14 09:00:11 PDT 2007


En/na Roman Goj ha escrit:
> Hi!
> 
> Finally I managed to cook up something which should actually be useful
> :) (contrary to the previous "processing time improvement" patch...
> btw. is it not ok? it didn't get comitted... )

You do well noticing it. Please, resend the mail with a [PATCH] in 
the subject. I often filter the inbox with patch to see if they all 
are served.

In this case I think David will do the honours... ;)

> I learned to use valgrind (Pau, thanks for the tip, I would have had
> doubts whether to use it or try anything else :) ) ... and it turns
> out that right after fftw_execute, the biggest memory hog is the []
> operator in std::vector and since _spectrum is a vector and it has to
> be assigned literally millions of times in ConstantQTransform.cxx,
> TonalAnalysis.cxx and FourierTransform.cxx I thought optimizing that
> was the way to go.
> 
> The hack I did seems a bit dirty (at least to me)
> double * spectrumArray = &_spectrum[0];
> and then instead of calling _spectrum[i] I call spectrumArray[i]
> and this turns out to be something like 5 times faster... I guess
> iterators would have been a nicer way to do this, but I think they
> would also be slower...

At first sight it seems to me that you are getting the
debug-asserts penalty. Are you sure you are compiling with release=1?

> This site: (quite interesting, a nice find :) )
> http://www.gotw.ca/gotw/050.htm
> says this method is actually quite valid :) (should I dwelve deeper in
> the site and maybe use the later tips also?)
> 
> Plus there were two loops which called frameSize() like this:
> for(i=0; i<frameSize(); i++)
> and it turns out the compiler isn't intelligent enough to optimize
> this (I never cared about this, always thought gcc would take care of
> this for me, I'm disappointed :( ) and calls frameSize everytime the
> stopping condition is evaluated... so I put the result of frameSize()
> in a variable and used that (a couple percent of improvement)

Again, I'd be puzzled if g++ is not able to inline such a getter! I 
really hope you where compiling in debug mode.

The FFTW plan optimization think sounds very good to me.
David, what do you think?

pau




More information about the clam-devel mailing list