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: Muthiah Annamalai
Subject: Re: Calling octave functions from oct-files
Date: Sat, 12 Jan 2008 23:28:23 -0600
User-agent: Thunderbird 2.0.0.6 (X11/20071022)

Evan 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 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?
_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave


I think numbers maybe wrong here. You are adding the DLD-loading time
as well. So you better do something like autoload('fun1','fun1.oct') before
running your profiles.
-Muthu



reply via email to

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