help-octave
[Top][All Lists]
Advanced

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

Re: interp1 OCT file


From: Jaroslav Hajek
Subject: Re: interp1 OCT file
Date: Fri, 2 Jul 2010 21:51:51 +0200

On Fri, Jul 2, 2010 at 5:29 PM, Luke M <address@hidden> wrote:
>
> Hello all,
>
> As an exercise to help me learn to write oct files, I partially implemented
> interp1 in C++.  Please have a look at the code here (130 lines, didn't want
> to breach length etiquette):
>
> http://pastebin.com/CTkSBfVc http://pastebin.com/CTkSBfVc
>
> I learned the following in the course of developing:
>
> - Minimizing the use of charMatrix (using enum for interpolation type) sped
> the code up a lot.  It's only still there for compatibility with interp1.
> - Reading in the arguments as ColumnVectors instead of NDArrays sped up the
> code considerably (~3-4x).
> - Removing the check for monotonic input gave an extra 20% boost.
> - Some linear interpolation benchmarks against interp1 and interp1q:
>
> x = [0:1:1000]'; y = sort(rand(length(x),1)); xi = [12.5:6.7:900]';
> 10000 interp1's: 6.32674 seconds.
> 10000 interp1q's: 3.26641 seconds.
> 10000 ointerp1's: 0.831889 seconds.
> 10000 ointerp1q's: 0.632212 seconds.
> x = [0:1:10000]'; y = sort(rand(length(x),1)); xi = [12.5:6.7:9000]';
> 1000 interp1's: 1.23987 seconds.
> 1000 interp1q's: 0.865512 seconds.
> 1000 ointerp1's: 0.734048 seconds.
> 1000 ointerp1q's: 0.640468 seconds.
> x = [0:1:100000]'; y = sort(rand(length(x),1)); xi = [12.5:6.7:90000]';
> 1000 interp1's: 6.05447 seconds.
> 1000 interp1q's: 4.54011 seconds.
> 1000 ointerp1's: 9.2129 seconds.
> 1000 ointerp1q's: 7.56058 seconds.
>
> Does anybody have any tips on squeezing extra speed out of it, especially
> for longer input vectors?
>

Here are several tips:

Use const declarations for read-only arrays. This eliminates the
unnecessary aliasing check.

When writing to an array that is known to be unaliased, you may use
the xelem method. Alternatively, use the NoAlias template wrapper for
the array.

Any serious speed benchmarks should be done against the development
sources. Please give also a short indication of your machine and
compiler settings used.

It is generally not acceptable to abandon functionality (e.g.
monotonicity check) of standard funcs in lieu of performance.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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