From help-request at octave dot org Sat Feb 5 03:08:53 2005 Subject: Re: octave-speed From: "Paul Thomas" To: =?iso-8859-1?Q?Rafael_Rodr=EDguez_Velilla?= , Date: Sat, 5 Feb 2005 10:13:36 +0100 Rafael, I was curious as to just what performance improvement could be obtained with a little C++ routine, so....... here it is. It si bare bones, has no error or parameter checking but it works. The commented out line uses the cmath library sqrt, instead of calling the octave sqrt through feval. The times are: Original in octave 5.2s C++ call octave sqrt 0.58s C++ call cmath sqrt 0.16s The octave part- tic; Ns = 1e5; m = [1:(Ns-1)]; T = (sqrt (m .* (m+1))); n = zeros (1, Ns); n(1) = 8; n = funct_iter ("sqrt", T, n); %call to .oct function printf ("time=%g\n", toc); printf ("n=%g\n", n(Ns)); and funct_iter.cpp - #include #include #include DEFUN_DLD (funct_iter, args,, "Function iteration demo") { octave_value_list retval; std::string fcn = args( 0 ).string_value(); ColumnVector T(args (1).vector_value ()); ColumnVector n(args (2).vector_value ()); int Ns = n.rows (); for (int i = 0; i < (Ns - 1); i++) { octave_value argi (T(i)*n(i)); octave_value_list fargs (argi); /* feval returns an octave_value_list, (0) picks out the 1st item on the list and scalar_value () converts it into a scalar */ n(i+1) = feval (fcn, fargs, 1)(0).scalar_value (); /* n(i+1) = sqrt (n(i)*T(i)); */ } retval(0) = n; return retval; } ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------