This is a static copy of a profile report

Home

mpower>integerMpower (Calls: 1, Time: 0.002 s)
Generated 16-Jul-2020 17:08:32 using performance time.
subfunction in file /Applications/MATLAB_R2020a.app/toolbox/matlab/ops/mpower.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
mpowerfunction1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
66
if rem(p,2) == 1 %if odd
100.000 s23.7%
65
while p > 0
10.000 s15.1%
78
end
100.000 s12.5%
67
if first
60.000 s12.4%
75
if p ~= 0
100.000 s10.0%
All other lines  0.001 s26.4%
Totals  0.002 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function28
Non-code lines (comments, blank lines)4
Code lines (lines that can run)24
Code lines that did run22
Code lines that did not run2
Coverage (did run/can run)91.67 %
Function listing
time 
Calls 
 line
  55 
function Z = integerMpower(X,y)
< 0.001 
      1 
  56
if y == 0 
  57 
    Z = eye(size(X),'like',X([])); %always real
< 0.001 
      1 
  58
else 
  59 
    % X and y can be sparse
  60 
    % Z = X^y for integer y. Use repeated squaring.
  61 
    % For example: A^13 = A^1 * A^4 * A^8
< 0.001 
      1 
  62
    p = abs(y); 
< 0.001 
      1 
  63
    D = X; 
< 0.001 
      1 
  64
    first = true; 
< 0.001 
      1 
  65
    while p > 0 
< 0.001 
     10 
  66
        if rem(p,2) == 1 %if odd 
< 0.001 
      6 
  67
            if first 
< 0.001 
      1 
  68
                Z = D;  % hit first time. D*I 
< 0.001 
      1 
  69
                first = false; 
< 0.001 
      5 
  70
            else 
< 0.001 
      5 
  71
                Z = D*Z; 
< 0.001 
      6 
  72
            end 
< 0.001 
     10 
  73
        end 
< 0.001 
     10 
  74
        p = fix(p/2); 
< 0.001 
     10 
  75
        if p ~= 0 
< 0.001 
      9 
  76
            D = D*D; 
< 0.001 
     10 
  77
        end 
< 0.001 
     10 
  78
    end 
< 0.001 
      1 
  79
    if y < 0 
  80 
        Z = inv(Z);
< 0.001 
      1 
  81
    end 
< 0.001 
      1 
  82
end 

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