Skip to content

Optimal code metric values for P4 programs #5326

Open
@stan-leetasi

Description

@stan-leetasi

Recently, new functionality was added to the compiler, which allows for collecting code metrics from compiled programs, in PR #5250. Implementing this functionality was part of my bachelor's thesis.

As a part of my thesis, I also conducted an empirical analysis of code metric values from public P4 programs sourced from the P4Guide and P4Tutorials repositories. The goal was to determine optimal metric values and the upper acceptable thresholds for metric values of P4 programs. The final results are in the tables below.

Optimal values

Metric Mean Median
Lines of Code 164.20 154.00
Cyclomatic Complexity 21.22 18.00
Halstead Metrics
Unique Operators 28.61 25.00
Unique Operands 60.78 53.00
Total Operators 192.33 159.00
Total Operands 204.37 176.00
Vocabulary 89.39 89.00
Length 396.71 327.00
Difficulty 47.53 35.58
Volume 2714.79 2090.29
Effort 216974.81 75213.00
Estimated Bugs 0.90 0.70

Maximum acceptable values

Metric Threshold
Cyclomatic Complexity 42.00
Halstead Metrics
Unique Operators 40.00
Unique Operands 113.00
Total Operators 446.00
Total Operands 443.00
Vocabulary 137.00
Length 928.00
Difficulty 90.46
Volume 6760.85
Effort 527913.00
Estimated Bugs 2.25

The detailed explanation of how the analysis was conducted, and graphs visualising the data can be found in my thesis.

I am opening this issue because I think that this data is an useful reference point for utilizing the code metric collection functionality. If you have any suggestions about where I should post this, please let me know.

I am also including some of the graphs which visualize the collected data.

Image
Image
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions