[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
execution speed in *oct files
From: |
A+A Adler |
Subject: |
execution speed in *oct files |
Date: |
Thu, 3 Jun 1999 20:32:14 -0400 (EDT) |
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?
Why are pointers so much more efficient than
matrix refernces?
Should I go back to all my other time critical
*.oct files and re-write them to take
advantage of this?
______________________________________________________________
Andy Adler, address@hidden
---------------------------------------------------------------------
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
---------------------------------------------------------------------