bugGNU Octave - Bugs: bug #64898, Slow zeros

 
 

bug #64898: Slow zeros

Submitter:  None
Submitted:  Wed 15 Nov 2023 06:52:10 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  None Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 8.3.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 20 Nov 2023 08:56:31 PM UTC, comment #2: 


;A(1)=1;


That will probably only make the OS allocate one page of about 4kb, in Matlab. The zero pages are usually lazy.

In the end if the matrix is used in all elements I guess the runtime will be about twice as fast with calloc() as the first memset() is redundant for zeros. But only for a small matrix. I don't think there are 3Gb of zeroed pages available most of the time.

Could you try:

tic;A=zeros(20000);A(:,:)=1;toc

in Matlab and compare to Octave on you computer.

Petter <petter>
Wed 15 Nov 2023 07:53:30 PM UTC, comment #1: 

The array classes in Octave currently use std::fill_n from the STL. If you want to explore, look in Array-base.cc in the fill functions around line 100.

Your test code for me takes 0.5 seconds.

Arun Giridhar <arungiridhar>
Group Member
Wed 15 Nov 2023 06:52:10 PM UTC, original submission:  

While pondering the slowness of mxCreateNumericArray in #64882, I wondered if Octave proper suffered the same issue. Yes it does.
In Octave:

>> tic;A=zeros(20000);A(1)=1;toc
Elapsed time is 2.16837 seconds.
--verbatim

*In Matlab:*
++verbatim++
>> tic;A=zeros(20000);A(1)=1;toc
Elapsed time is 0.000268 seconds.

A simple calloc in C code with the same size is the same speed as Matlab whereas malloc + memset is the same speed as Octave.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by petter (Posted a comment)
  • -email is unavailable- added by arungiridhar (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-3e34.
    Corresponding source code