본문 바로가기
note/code complexity

About LOC, HCM, CCM

by 눈부신음표 2022. 2. 17.
728x90

Lines of Code(LOC)

counting the number of lines

- advantages

    - easy to understand, fast to count and independent of the program language

- disadvantages

    - ignores the different complexity of each code line, ignores the structure of the software such as branches and jumps, doesn't take the difference of the programmers' abilities into account

- two types of LOC
    - Physical LOC: nb of lines including comment lines, sensitive to formatting and coding style

    - Logical LOC: nb of executable statements, less sensitive to formatting and coding style


Halstead Complexity Metric(HCM)

use scientific methods to analyze the characteristics and structure of the software.

caculated on the count of the operators and operands

- \(n_{1}\) = the number of distinct operators

- \(n_{2}\) = the number of distinct operands

- \(N_{1}\) = the total number of operators

- \(N_{2}\) = the total number of operands

- several measures can be calculated:

    - program vocab: \(n = n_{1} + n_{2}\)

    - program length: \(N = N_{1} + N_{2}\)

    - calculated estimated program length: \(\hat{N} = n_{1} log_{2}n_{1} + n_{2} log_{2}n_{2}\)

    - volume: \(V = N \times log_{2}n\)

    - difficulty: \(D = \frac{n_{1}}{2} \times \frac{N_{2}}{n_{2}}\)

    - effort: \(E = D \times V\)

    - time required to program: \(T = \frac{E}{18}\) seconds

    - Number of delievered bugs: \(B = \frac{V}{3000}\) (the value 3000 means the programmer's ability: S*)

Example: https://en.wikipedia.org/wiki/Halstead_complexity_measures

- advantages

    - easy to calculate, has nothing to do with the program language, can be used to forecast the but density(B)

- disadvantages

    - only considers the complexity from the data stream, while ignores the complexity from the control flow ( codes with som branches and jumps are more complex ), the value of S* is too rigid

 

Weighted Halstead Complexity Metric(WHCM)

gives different operators different weights

gives different operands different weights


Cyclomatic Complexity Metric

measurement of the complexity of a module's decision structure graph

- for a single program, if control flow graph has e edges and n nodes, CCM value \(V(G) = e - n + 2\)

- advantages

    - strong connection between the bug density and the CCM

- disadvantages

    - ignores the complexity from the dataflow( in practice, HCM and CCM are usually used together, HCM is used to measure dataflow and CCM is used to measure control flow ), ignores complexity of nested code, doesn't distinguish complexities of different kinds of control flow.

728x90

댓글