help-octave
[Top][All Lists]
Advanced

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

Re: Calling octave functions from oct-files


From: Evan
Subject: Re: Calling octave functions from oct-files
Date: Mon, 14 Jan 2008 14:33:06 +0800

On Jan 13, 2008 3:00 PM, Evan <address@hidden> wrote:
>
> On Jan 13, 2008 2:30 PM, John W. Eaton <address@hidden> wrote:
> >
> > On 13-Jan-2008, Evan wrote:
> >
> > | I am converting some part of my program from octave scripts to
> > | oct-files in order to improve performance. I find that I have to call
> > | octave functions in a for loop. And if I use "feval" to do this, it
> > | consumes a lot of time. The result is that the oct-file is even slower
> > | than the octave script. So I wonder if there is an another way to call
> > | octave functions. For example, can I get the pointer to the function,
> > | then just use (*p)(args) to call the function?
> >
> > No.
> >
> > Maybe you could give a complete (but short) example that shows what
> > you are trying to do?  I don't think feval from a .oct file should be
> > slower than running an interpreted script.
> >
>
> What I am trying to do is something like
>
> for (i = 0; i < n; i++)
>   {
>     quad_args(2) = xf(i);
>     feval ("quad", quad_args, 4);
>   }
>
> It turns out to be slower than the corresponding script
>
>
> I also tried the following examples
>
> // fun1.cc
> #include <octave/oct.h>
> #include <octave/parse.h>
>
> DEFUN_DLD (fun1, args, , "fun1")
> {
>   return feval("sin", octave_value (3), 1);
> }
> //end of fun1.cc
>
> // fun2.cc
> #include <octave/oct.h>
> #include <octave/parse.h>
>
> DEFUN_DLD (fun2, args, , "fun2")
> {
>   int state;
>   return eval_string ("sin(3)", true, state, 1);
> }
> // end of fun2.cc
>
> I compared the runing time of fun1, fun2 and sin(3) in octave by
> tic; fun1; toc
> tic; fun2; toc
> tic; sin(3); toc

I made a mistake here. I should have compared fun1, fun2 with fun3
defined as below, instead of with sin(3)

function y = fun3 ()
  y = sin(3);
endfunction

fun1, fun2 have comparable running time with fun3

> I find that fun1 and fun2 are hundreds of times slower than sin(3).
> (I have taken into account the time consumed by "tic;toc")
>
> any ideas?
>


reply via email to

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