help-octave
[Top][All Lists]
Advanced

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

Re: associative array


From: Francesco Potortì
Subject: Re: associative array
Date: Sat, 28 Mar 2020 21:03:14 +0100

I managed to recreate the problem with a simple program.  It shows that
isfield execution time grows linearly with the size of the struct if
isfield is called after creating a new field.  The printout (times and
time differences) shows that indeed the total time grows quadratically
with struct size.

Unless someone comes out with a reasonable explanation, I'll signal this
as a bug in isfield.

======================= isfield_bench.m ========================
e = 4;
a = struct;
t = zeros(1,10);

profile off; profile clear; profile on
for i = 1:10
  for j = 1:10^(e-1)
    f = sprintf("%.11f",rand);
    if !isfield(a,f)
      a.(f) = [];
    endif
  end
  t(i) = cputime;
end
profile off; profshow(4)

numfields(a)
[t(2:end)'-t(1), diff(t')]
================================================================

octave> isfield_bench
   # Function Attr     Time (s)   Time (%)        Calls
-------------------------------------------------------
   5  isfield            26.787      98.65        10000
   4  sprintf             0.178       0.66        10000
   3     rand             0.171       0.63        10000
   6 prefix !             0.018       0.07        10000
ans =  10000
ans =
    1.0021    1.0021
    2.5191    1.5170
    4.5951    2.0760
    7.2258    2.6308
   10.4104    3.1846
   14.1473    3.7369
   18.4348    4.2875
   23.2898    4.8551
   28.6780    5.3882

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it



reply via email to

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