[bug #68121] convert isequal to built-in function for performance
"Dmitri A. Sergatskov" <[email protected]> Mon, 4 May 2026 19:47:05 -0400 (EDT)
| Newsgroups | gmane.comp.gnu.octave.bugs |
|---|---|
| Message-ID | <[email protected]> |
Please use the bug tracker to post updates to a bug report. The mailing list is intended as a read-only notification stream. Info posted to this mailing list address won't appear in the tracker database where it is most useful.
Follow-up Comment #29, bug #68121 (group octave):
Here is my proposal.
(file isequal_vmethod_20260504_200.diff)
it implements `isequal()` as a virtual method, so lots of files get touched.
With attached benchamrk
(file bench_isequal.m) I see (on Ultra 9 285 CPU) before:
octave:1> bench_isequal
empty loop (1e6) : 0.0225 s
isequal(1,1) (1e6) : 15.9582 s
double 5000x5000 equal x50 : 0.8293 s
double 5000x5000 differ x50 : 0.7901 s
single 5000x5000 equal x50 : 0.4861 s
int32 5000x5000 equal x50 : 0.4847 s
logical 5000x5000 equal x50 : 0.2531 s
complex 5000x5000 equal x50 : 1.3389 s
char 5000x5000 equal x50 : 0.0659 s
sparse 5000x5000 equal x200 : 0.7049 s
isequaln 5000x5000 w/ NaN x50 : 2.1113 s
cell 1x10000 (scalars) x100 : 17.3372 s
struct 3x500x500 x200 : 0.0705 s
After:
octave:1> bench_isequal;
empty loop (1e6) : 0.0223 s
isequal(1,1) (1e6) : 0.8347 s
double 5000x5000 equal x50 : 0.5819 s
double 5000x5000 differ x50 : 0.5240 s
single 5000x5000 equal x50 : 0.2621 s
int32 5000x5000 equal x50 : 0.2580 s
logical 5000x5000 equal x50 : 0.0664 s
complex 5000x5000 equal x50 : 1.0598 s
char 5000x5000 equal x50 : 0.0626 s
sparse 5000x5000 equal x200 : 0.2884 s
isequaln 5000x5000 w/ NaN x50 : 0.6700 s
cell 1x10000 (scalars) x100 : 0.0240 s
struct 3x500x500 x200 : 0.0473 s
Also some benchmarks previously on this report:
octave:2> M = randi([1 10],9)-1;
octave:3> tic,for idx = 1:100, M==M;endfor,toc
Elapsed time is 5.48363e-05 seconds.
octave:4> tic,for idx = 1:10000, all(M(:));endfor,toc
Elapsed time is 0.0139458 seconds.
octave:5> tic,for idx = 1:10000, isequal(M,M);endfor,toc
Elapsed time is 0.0095439 seconds.
octave:6> s1 = ['a', 'b'; 'c', 'd']
s1 =
ab
cd
octave:7> s2 = ['a', 'b'; 'e', 'f']
s2 =
ab
ef
octave:8> isequal(s1,s2)
ans = 0
octave:9> a = randi(250, 1e4, 1e4, "uint8");
octave:10> b = a + uint8(1);
octave:11> c = b - uint8(1);
octave:12> tic; isequal(a, b), toc
ans = 0
Elapsed time is 3.69549e-05 seconds.
octave:13> tic; isequal(a, c), toc
ans = 1
Elapsed time is 0.00641489 seconds.
Dmitri.
--
(file #58549, file #58550)
_______________________________________________________
Additional Item Attachment:
Name: isequal_vmethod_20260504_200.diff Size: 62KiB
<https://file.savannah.gnu.org/file/isequal_vmethod_20260504_200.diff?file_id=58549>
Name: bench_isequal.m Size: 3.7KiB
<https://file.savannah.gnu.org/file/bench_isequal.m?file_id=58550>
AGPL NOTICE
These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-c36938be85ff6c1b727bc7dd7fd30e48f9142870.tar.gz
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?68121>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCafkv+QAKCRCqLAuaBUf3 TqmTAP9td7kxn6JZh1Hksqpnx1T/vIFxZNSJa8az6y6LP2Z9RwD9F+XfQzhQjpBP vq1G4ApZENaERRtd9d8VcHpe1en11ww= =aWnu -----END PGP SIGNATURE-----