help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

execution speed in *oct files


From: John W. Eaton
Subject: execution speed in *oct files
Date: Fri, 4 Jun 1999 00:40:11 -0500 (CDT)

On  3-Jun-1999, A+A Adler <address@hidden> wrote:

| I just submitted an oct file for 2-D convolutions
| to octave-sources.
| 
| While I was writing it, I noticed that the standard octave
| syntax seems to be very inefficient.
| 
| For example the inner loop as I originally had it
| (A,B are Matrix, sum is double, all else are int)
| 
|        int           bi  = Bm - 1 - MAX(0, edgM-oi);
|        int           ai  = MAX(0, oi-edgM); 
| 
|        while( bi >= 0 && ai < Am ) {
| 
|           sum+= A(ai,aj) * B(bi,bj);
| 
|           bi--; ai++;
| 
|        } // for( int bi=0; 
| 
| This gave performance of half of the comparable MATLAB code.
| So I figured there had to be some way to do better.
| Finally, I found that by using pointers instead of
| directly refering to matrix elements I could get a 
| speed up of more than three times!
| 
| My code now looks like this
| 
|        int           bi  = Bm - 1 - MAX(0, edgM-oi);
|        int           ai  = MAX(0, oi-edgM); 
|        const double* Ad  = A.data() + ai + Am*aj;
|        const double* Bd  = B.data() + bi + Bm*bj;
| 
|        while( bi >= 0 && ai < Am ) {
| 
|           sum+= (*Ad) * (*Bd);
| 
|           bi--; Bd--; ai++; Ad++;
| 
|        } // for( int bi=0; 
| 
| Questions: Is this just a feature of the i686 I'm using?

Probably not.

|            Why are pointers so much more efficient than
|              matrix refernces?

Because the indexing operators invoke some functions to do the
indexing calculation.  I'd guess that either the functions are not all
inlined, or the compiler is not able to convert the addition and
multiplication of the indexing operation to a simple increment (as you
have), or both.

|            Should I go back to all my other time critical
|              *.oct files and re-write them to take 
|              advantage of this?

Perhaps.

I think that what Octave's Matrix classes really need to do this
correctly are iterators.

jwe



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]