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

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

[Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (a


From: Rik
Subject: [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))"
Date: Tue, 29 Nov 2022 12:19:25 -0500 (EST)

URL:
  <https://savannah.gnu.org/bugs/?63444>

                 Summary: "if (COND)" is much slower than "if (all (COND))"
                 Project: GNU Octave
               Submitter: rik5
               Submitted: Tue 29 Nov 2022 09:19:23 AM PST
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Performance
                  Status: Confirmed
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: dev
         Discussion Lock: Any
        Operating System: Any
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Tue 29 Nov 2022 09:19:23 AM PST By: Rik <rik5>
This observation came up in another bug report, but it deserves its own issue
report.  The use of an implicit call to all() in an if statement is 35% slower
than directly calling all().  This seems rather strange and hopefully is
trivial to fix.

Test code I used is attached as bm_implicit_all.m and reproduced here:


N = 1e3;

data = ones (1e6, 1);

tic;
for i = 1:N
  if (data)
  endif
endfor
bm1 = toc

tic;
for i = 1:N
  if (all (data))
  endif
endfor
bm2 = toc
And a sample test run is
bm_implicit_all
bm1 = 1.9310
bm2 = 1.2500
octave:14> pctchg (bm1, bm2)
ans = -35.266


The function "pctchg" is my own local function that calculates the percentage
change of two values.






    _______________________________________________________
File Attachments:


-------------------------------------------------------
Date: Tue 29 Nov 2022 09:19:23 AM PST  Name: bm_implicit_all.m  Size: 148B  
By: rik5

<http://savannah.gnu.org/bugs/download.php?file_id=54038>

    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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