octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #64840] VM __vm_enable__ seems to have not neg


From: Petter
Subject: [Octave-bug-tracker] [bug #64840] VM __vm_enable__ seems to have not negligible overhead losses (~5%) in certain situations
Date: Tue, 31 Oct 2023 18:10:51 -0400 (EDT)

Follow-up Comment #1, bug #64840 (project octave):

I looked through quadv I think it is the calls to feval() that causes the
slowdown from using auto-compilation. feval() is C++ code and new vm is
allocated when feval() in turn calls the bytecode for 'sin(x)'.
Allocating a vm is not that much work, but it slows down a bit.

Chaning feval() to calling the handle directly makes auto-compilation somewhat
faster than just compiling quadv and its subfunctions.

Making the runtime:
Elapsed time is 4.86418 seconds.
Elapsed time is 2.4246 seconds.
Elapsed time is 2.82154 seconds.

I guess feval could be a m-file instead that calls some __feval__
on string arguments, or something.


# HG changeset patch
# User Petter
# Date 1698789394 -3600
#      Tue Oct 31 22:56:34 2023 +0100
# Node ID 29bee433180c18d79ecb4aa524592461e422ee5f
# Parent  90f4180748f93d133fedb90b8b66f52701acae61
wip quadv call handles directly not a patch for submitting

diff -r 90f4180748f9 -r 29bee433180c scripts/general/quadv.m
--- a/scripts/general/quadv.m   Tue Oct 31 20:36:43 2023 +0100
+++ b/scripts/general/quadv.m   Tue Oct 31 22:56:34 2023 +0100
@@ -76,6 +76,10 @@
     print_usage ();
   endif
 
+  if ischar (f)
+    f = @(varargin) feval (f, varargin);
+  end
+
   if (isa (a, "single") || isa (b, "single"))
     eps = eps ("single");
   else
@@ -103,23 +107,24 @@
   c2 = (a + b)  / 2;
   c3 = (b2 + b) / 2;
 
-  fa  = feval (f, a,  varargin{:});
-  fc1 = feval (f, c1, varargin{:});
-  fb1 = feval (f, b1, varargin{:});
-  fc2 = feval (f, c2, varargin{:});
-  fb2 = feval (f, b2, varargin{:});
-  fc3 = feval (f, c3, varargin{:});
-  fb  = feval (f, b,  varargin{:});
+  fa  = f (a,  varargin{:});
+  fc1 = f (c1, varargin{:});
+  fb1 = f (b1, varargin{:});
+  fc2 = f (c2, varargin{:});
+  fb2 = f (b2, varargin{:});
+  fc3 = f (c3, varargin{:});
+  fb  = f (b,  varargin{:});
+
   nfev = 7;
 
   ## NOTE: If there are edge singularities, move edge point by eps*(b-a) as
   ## discussed in Shampine paper used to implement quadgk.
   if (any (isinf (fa(:))))
-    fa = feval (f, a + eps * (b-a), varargin{:});
+    fa = f (a + eps * (b-a), varargin{:});
     nfev++;
   endif
   if (any (isinf (fb(:))))
-    fb = feval (f, b - eps * (b-a), varargin{:});
+    fb = f (b - eps * (b-a), varargin{:});
     nfev++;
   endif
 
@@ -169,8 +174,8 @@
 
   d = (a + c) / 2;
   e = (c + b) / 2;
-  fd = feval (f, d, varargin{:});
-  fe = feval (f, e, varargin{:});
+  fd = f (d, varargin{:});
+  fe = f (e, varargin{:});
   nfev += 2;
   q1 = (c - a) / 6 * (fa + 4*fd + fc);
   q2 = (b - c) / 6 * (fc + 4*fe + fb);




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?64840>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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