[bug #68458] Improve GCD code for style and performance

"Dmitri A. Sergatskov" <[email protected]> Thu, 18 Jun 2026 11:08:34 -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 #1, bug #68458 (group octave):

The CSET (file bug68458_gcd_20260618_100.cset) is attached.
With it apply I see:
Before:

octave:1> rand("seed", 42)
octave:2> a = randi ([0, 2^32-1], 1, 1e7); b = randi ([0, 2^32-1], 1, 1e7);
octave:3> tic; g = gcd (a, b); toc
Elapsed time is 1.49398 seconds.
...
octave:1> rand("seed", 42)
octave:2> a = complex (randi ([-1000, 1000], 1, 1e7),randi ([-1000, 1000], 1,
1e7));
octave:3> b = complex (randi ([-1000, 1000], 1, 1e7),randi ([-1000, 1000], 1,
1e7));
octave:4> tic; g = gcd (a, b); toc
Elapsed time is 1.52245 seconds.


After:

octave:1> rand("seed", 42)
octave:2> a = randi ([0, 2^32-1], 1, 1e7); b = randi ([0, 2^32-1], 1, 1e7);
octave:3> tic; g = gcd (a, b); toc
Elapsed time is 0.564844 seconds.
...
octave:1> rand("seed", 42)
octave:2> a = complex (randi ([-1000, 1000], 1, 1e7),randi ([-1000, 1000], 1,
1e7));
octave:3> b = complex (randi ([-1000, 1000], 1, 1e7),randi ([-1000, 1000], 1,
1e7));
octave:4> tic; g = gcd (a, b); toc
Elapsed time is 1.17304 seconds.


Perhaps Complex can be optimized further, but it is much trickier / more
involve. May be this is good for now.

Dmitri.
-- 


(file #58729)

    _______________________________________________________

Additional Item Attachment:

Name: bug68458_gcd_20260618_100.cset Size: 3.0KiB

<https://file.savannah.gnu.org/file/bug68458_gcd_20260618_100.cset?file_id=58729>


    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/?68458>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCajQJ8gAKCRCqLAuaBUf3
TsRYAP95wKWYc8P67KN9/gFE5PrBXHIWrzaSf74SSz+YYTtveQD/W44fpRqudk+T
4zTlFh0ytKLP7BiEG24k6VnTSiV75Qw=
=MTo5
-----END PGP SIGNATURE-----