Halstead 复杂度

Posted by Nino Lau on April 21, 2019

计算下列代码片段的 Halstead 复杂度的 11 项内容。


Operator Number of Occurrences Operand Number of Occurrences
If 1 month 3
< 1 year 5
+= 1 dayray 1
- 1 day 1
+ 6 3 1
* 2 12 1
/ 4 1 1
% 1 26 1
n1 = 8 N1 = 17 10 1
    4 1
    6 1
    100 1
    400 1
    7 1
    n2 = 14 N2 = 20

  • n1 = 8, n2 = 14, N1 = 17, N2 = 20
  • Program vocabulary: n = n1 + n2 = 22
  • Program length: N = N1 + N2 = 37
  • Program volume: V = Nlog2(n) = 164.9978
  • Program level: L^ = (2/n1) * (n2/N2) = 0.175
  • Program difficulty: D = 1/L^ = 5.7143
  • Program Effort: E = V * D = V/L^ = 942.8446
  • Language level: Lʹ = L^ \* L^* V = 5.0531
  • Program Time(hours): T^ = E/(S * f) = 0.0145
  • 平均语句大小: N/语句数 = 9.25
  • 程序中的错误数预测值:
  • B = V/3000 = Nlog2(n)/3000 = 0.0550