Halstead 复杂度分析

题目

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

if (month < 3) {
month += 12;
–year;
}
return dayray((int)(day + (month + 1) * 26/10 + year +
year/4 + 6 * (year/100) + year/400)% 7);

答案

  • 操作符

    OperatorNumber of OccurrencesOperatorNumber of Occurrences
    if1+6
    <1*2
    +=1/4
    -1%1
    return1dayray1
    int1
    n1=11N1=20
  • 操作数

    OperandNumber of OccurrencesOperandNumber of Occurrences
    month3261
    31101
    12141
    year561
    day11001
    114001
    71
    n2=13N2=19
  • 计算

    • 词汇表长度(Program vocabulary ):n = n1+n2 = 24
    • 程序长度或简单长度(Program length ):N = N1+N2 = 39
    • 程序的预测长度(Calculated program length):N^ = 11*log2(11)+13*log2(13)=86.1594641399
    • 程序体积或容量(Volume ):V=N*log2(n)= 39*log2(24)= 178.8135375273
    • 程序级别(Level ):L^ = (2/n1)*(n2/N2)= (2/11)*(13/19)=0.1244019138755980861244019138756
    • 程序难度(Difficulty ):D = 1/L^ = 8.0384615384615384615384615384614
    • 编程工作量(Effort ):E = V*D = 1437.38574396945
    • 语言级别:L’ = L*L*V = 2.7672890128077379180879558618164
    • 编程时间(hours ):T^ = E/(S*F) = 0.02218187876496064814814814814815
    • 平均语句大小:N / 语句数 = 39/4 = 9.75
    • 程序中的错误数预测值:B = V / 3000 = 0.0596045125091
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值