[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 15:02:26 -0500 (EST) |
Follow-up Comment #6, bug #63444 (project octave):
I made another octfile which tests how much time the test for isnan() adds.
It turns out that this seems to be a bigger portion of the slowdown (20%) than
the actual loopisg structure (1x or 2x).
The file is shown below and attached as loop_tst_nan.cc
#include <octave/oct.h>
DEFUN_DLD (loop_tst_nan, args, nargout,
"Test single or double loop equivalent to all()\n"
"ARG1 : TRUE/FALSE, test for NaNs?\n"
"ARG2 : numeric array")
{
if (args.length () != 2)
print_usage ();
bool do_nan_test = args(0).bool_value ();
NDArray A = args(1).array_value ();
octave_idx_type N = A.numel ();
bool retval = true;
if (do_nan_test)
{
for (octave_idx_type i = 0; i < N; i++)
{
if (std::isnan (A(i)))
error ("loop2: Can not convert NaN to logical value");
if (! A(i))
retval = false;
}
}
else
{
for (octave_idx_type i = 0; i < N; i++)
{
if (! A(i))
retval = false;
}
}
return ovl (retval);
}
Results are
octave:4> tic; for i = 1:100, loop_tst_nan (0,x); end; toc
Elapsed time is 0.301775 seconds.
octave:9> tic; for i = 1:100, loop_tst_nan (1,x); end; toc
Elapsed time is 0.383141 seconds.
(file #54040)
_______________________________________________________
Additional Item Attachment:
File name: loop_tst_nan.cc Size:0 KB
<https://file.savannah.gnu.org/file/loop_tst_nan.cc?file_id=54040>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?63444>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", Rik, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", John W. Eaton, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", Rik, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", John W. Eaton, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", Rik, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", Rik, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))",
Rik <=
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", John W. Eaton, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", Rik, 2022/11/29
- [Octave-bug-tracker] [bug #63444] "if (COND)" is much slower than "if (all (COND))", John W. Eaton, 2022/11/29