octave-maintainers
[Top][All Lists]
Advanced

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

Re: Looking at Type inferencing compiler


From: David Bateman
Subject: Re: Looking at Type inferencing compiler
Date: Mon, 11 Dec 2006 23:24:02 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

John W. Eaton wrote:
> On 11-Dec-2006, David Bateman wrote:
> 
> | John W. Eaton wrote:
> | > On 11-Dec-2006, David Bateman wrote:
> | > 
> | > | So the only example above that is faster than the m-file is yours!!! Do
> | > | you or anyone else know where I'm paying the speed penalty for the
> | > | octave in-built classes? In any case I suspect that the improvement you
> | > | showed in the example in your thesis was largely due to the different
> | > | matrix class that the type inferencing, though further benchmarks will
> | > | be needed to prove that.
> | > 
> | > |     inline operator octave_value(){ 
> | > |         Matrix m(rows,cols); for (int i = 0; i<rows; ++i) for ( int j = 
> 0 ; j<cols; ++j ) m(i,j) = rep[i][j];
> | > |         return m;
> | > |     };
> | > 
> | > It's not clear to me whether this conversion operator is being used,
> | > but it will be slow because the indexing operator for the Matrix class
> | > must check the reference count each time it is called.  You can fix
> | > that by doing
> | > 
> | >   inline operator octave_value(){ 
> | >     Matrix m(rows,cols);
> | >     double *mp = m.fortran_vec ();
> | >     int k = 0;
> | >     for (int j = 0 ; j<cols; ++j)
> | >       for (int i = 0; i<rows; ++i)
> | >         mp[k++] = rep[i][j];
> | >     return m;
> | >   }
> | > 
> | > jwe
> | > 
> | 
> | Ok, but it in fact makes the situation even slightly worse. Jens code
> | with the matrix class without reference counting is slightly faster
> | again. There are 10000 matrix multiplies and only one octave_value
> | method called, and so this is not a big additional cost however.. In
> | fact I can't easily measure it.
> 
> OK.
> 
> | In fact I think I can see why using intNDArray is so slow. The basic *
> | operator is given by
> | 
> |   octave_int<T>& operator *= (const octave_int<T>& x)
> |   {
> |     double t = static_cast<double> (value ());
> |     double tx = static_cast<double> (x.value ());
> |     ival = OCTAVE_INT_FIT_TO_RANGE (t * tx, T);
> |     return *this;
> |   }
> | 
> | and so everything is done in double and then reconverted to an int,
> | which is of course slower than a straight integer multiple as Jens used.
> 
> Yes, we have to use this (strange) definition for compatibilty with
> Matlab integer types.
> 
> | What I don't understand is that the version cast as Matrix is so much
> | slower than the m-file...
> 
> I don't see the same results.  Here is what I see.  This is with 2.9.9
> on a Debian system:
> 
>   octave:1> which cover
>   cover is the user-defined function from the file
>   /export/home/jwe/cover.m
>   octave:2> tic; cover (10000); toc
>   Elapsed time is 0.118790 seconds.
>   octave:3> tic; cover (10000); toc
>   Elapsed time is 0.117249 seconds.
>   octave:4> mkoctfile cover.cc
>   octave:5> which cover
>   cover is the dynamically-linked function from the file
>   /export/home/jwe/cover.oct
>   octave:6> tic; cover (10000, 1); toc
>   Elapsed time is 0.052383 seconds.
>   octave:7> tic; cover (10000, 1); toc
>   Elapsed time is 0.052185 seconds.
>   octave:8> tic; cover (10000, 2); toc
>   Elapsed time is 0.101036 seconds.
>   octave:9> tic; cover (10000, 2); toc
>   Elapsed time is 0.100266 seconds.
>   octave:10> tic; cover (10000, 3); toc
>   Elapsed time is 0.051735 seconds.
>   octave:11> tic; cover (10000, 3); toc
>   Elapsed time is 0.051765 seconds.
> 
> And this is with a binary built from the current CVS sources:
> 
>   octave:1> which cover
>   cover is the user-defined function from the file
>   /export/home/jwe/cover.m
>   octave:2> tic; cover (10000); toc
>   Elapsed time is 0.435867 seconds.
>   octave:3> tic; cover (10000); toc
>   Elapsed time is 0.432693 seconds.
>   octave:4> mkoctfile cover.cc
>   octave:5> which cover
>   cover is the dynamically-linked function from the file
>   /export/home/jwe/cover.oct
>   octave:6> tic; cover (10000, 1); toc
>   Elapsed time is 0.212341 seconds.
>   octave:7> tic; cover (10000, 1); toc
>   Elapsed time is 0.217140 seconds.
>   octave:8> tic; cover (10000, 2); toc
>   Elapsed time is 0.729240 seconds.
>   octave:9> tic; cover (10000, 2); toc
>   Elapsed time is 0.746391 seconds.
>   octave:10> tic; cover (10000, 3); toc
>   Elapsed time is 0.075066 seconds.
>   octave:11> tic; cover (10000, 3); toc
>   Elapsed time is 0.075783 seconds.

Ok, odd.. Also odd the differences you are seeing between 2.9.9 and
2.9.9+... In any case it doesn't seem worthwhile changing the type of
the matrix as Jens did, but rather just the loop counters. Also given
the definition of integer math relative to double math we can assume
that the results will be the same in any case... Ok..

D>



reply via email to

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