# benchmark for isfield
# Bug #58105
clear all
clc
format long g compact
tic

n = 2e3; # number of inner trials
t1 = t2 = zeros(1,10); # times

a = struct;
rand ("state", "reset");
profile off; profile clear; profile on
for i = 1:10
  f = num2str (rand(n,1), "%.11f");
  for j = 1:n
    a.(f(j,:)) = [];
  endfor
  t1(i) = cputime;
endfor
profile off; profshow(4)
numfield = numfields(a)
yy1 = diff (t1')

a = struct;
rand ("state", "reset");
profile off; profile clear; profile on
for i = 1:10
  f = num2str (rand(n,1), "%.11f");
  for j = 1:n
    if (! isfield (a, f(j,:)))
      a.(f(j,:)) = [];
    endif
  endfor
  t2(i) = cputime;
endfor
profile off; profshow(4)
numfield = numfields(a)
yy2 = diff (t2')

plot (1:9, yy1, 'bo-', "LineWidth",3, 1:9, yy2, 'ro-', "LineWidth",3)

