This is a static copy of a profile report

Home

tabular.tabular>tabular.createVariables (Calls: 2, Time: 0.004 s)
Generated 04-Jun-2021 04:11:14 using performance time.
class method in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\datatypes\tabular\@tabular\tabular.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
table.table>table.tableclass method2
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
398
vars{ii} = repmat(string(missi...
20.003 s64.9%
448
end
100.000 s6.0%
395
case {'doublenan' 'doubleNaN' ...
60.000 s4.5%
410
vars{ii} = zeros(nrows,1,type)...
40.000 s2.9%
391
type = types{ii};
100.000 s2.8%
All other lines  0.001 s18.9%
Totals  0.004 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
repmatfunction20.001 s29.4%
missing>missing.stringclass method20.000 s8.5%
missing>missing.missingclass method20.000 s3.8%
Self time (built-ins, overhead, etc.)  0.002 s58.3%
Totals  0.004 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function66
Non-code lines (comments, blank lines)15
Code lines (lines that can run)51
Code lines that did run21
Code lines that did not run30
Coverage (did run/can run)41.18 %
Function listing
time 
Calls 
 line
 384 
        function vars = createVariables(types,sz)
 385 
            % Create variables of the specified types, of the specified height,
 386 
            % for a preallocated table, filled with each type's default value.
< 0.001 
      2 
 387
            nrows = sz(1); 
< 0.001 
      2 
 388
            nvars = sz(2); 
< 0.001 
      2 
 389
            vars = cell(1,nvars); % a row vector 
< 0.001 
      2 
 390
            for ii = 1:nvars 
< 0.001 
     10 
 391
                type = types{ii}; 
< 0.001 
     10 
 392
                switch type 
< 0.001 
     10 
 393
                case {'double' 'single' 'logical'} 
< 0.001 
      4 
 394
                    vars{ii} = zeros(nrows,1,type); 
< 0.001 
      6 
 395
                case {'doublenan' 'doubleNaN' 'singlenan' 'singleNaN'} 
 396 
                    vars{ii} = NaN(nrows,1,extractBefore(lower(type),'nan'));
< 0.001 
      6 
 397
                case 'string' 
  0.003 
      2 
 398
                    vars{ii} = repmat(string(missing),nrows,1); 
< 0.001 
      4 
 399
                case 'cell' 
 400 
                    vars{ii} = cell(nrows,1);
< 0.001 
      4 
 401
                case 'datetime' 
 402 
                    vars{ii} = datetime.fromMillis(NaN(nrows,1));
< 0.001 
      4 
 403
                case 'duration' 
 404 
                    vars{ii} = duration.fromMillis(zeros(nrows,1));
< 0.001 
      4 
 405
                case 'calendarDuration' 
 406 
                    vars{ii} = calendarDuration(zeros(nrows,1),0,0);
< 0.001 
      4 
 407
                case 'categorical' 
 408 
                    vars{ii} = categorical(NaN(nrows,1));
< 0.001 
      4 
 409
                case {'int8' 'int16' 'int32' 'int64' 'uint8' 'uint16' 'uint32' 'uint64'} 
< 0.001 
      4 
 410
                    vars{ii} = zeros(nrows,1,type); 
 411 
                case {'cellstr' 'char'}
 412 
                    if type == "char"
 413 
                        % Special case: replace 'char' with 'cellstr', with a warning. A char
 414 
                        % array is tempting but not a good choice for text data in a table.
 415 
                        matlab.internal.datatypes.warningWithoutTrace(message('MATLAB:table:PreallocateCharWarning'));
 416 
                    end
 417 
                    % cellstr is a special case that's not actually a type name.
 418 
                    vars{ii} = repmat({''},nrows,1);
 419 
                otherwise
 420 
                    if nrows > 0 % lengthenVar requires n > 0
 421 
                        % Use lengthenVar to create a var of the correct height. Not
 422 
                        % all types have their name as a constructor, e.g. double.
 423 
                        % So instead of creating a scalar instance to lengthen,
 424 
                        % create an empty instance.
 425 
                        try
 426 
                            % Create 0x0, lengthenVar will turn it into an Nx1, but
 427 
                            % would turn a 1x0 into an  Nx0 empty.
 428 
                            emptyVar = eval([type '.empty(0,0)']);
 429 
                        catch ME
 430 
                            throwAsCaller(preallocationClassErrorException(ME,type));
 431 
                        end
 432 
                        % lengthenVar creates an instance of var_ii that is nrows-by-1,
 433 
                        % filled in with the default (not necessarily "missing") value.
 434 
                        try
 435 
                            vars{ii} = tabular.lengthenVar(emptyVar,nrows);
 436 
                        catch
 437 
                            % lengthenVar failed, but we can still create an nrows-by-0 instance.
 438 
                            vars{ii} = eval([type '.empty(nrows,0)']); % don't use reshape, may not be one
 439 
                        end
 440 
                    else
 441 
                        try
 442 
                            vars{ii} = eval([type '.empty(0,1)']);
 443 
                        catch ME
 444 
                            throwAsCaller(preallocationClassErrorException(ME,type));
 445 
                        end
 446 
                    end
< 0.001 
     10 
 447
                end 
< 0.001 
     10 
 448
            end 
< 0.001 
      2 
 449
        end 

Other subfunctions in this file are not included in this listing.