pytorch / examples
Unit Size

The distribution of size of units (measured in lines of code).

Intro
  • Unit size measurements show the distribution of size of units of code (methods, functions...).
  • Units are classified in four categories based on their size (lines of code): 1-20 (small units), 20-50 (medium size units), 51-100 (long units), 101+ (very long units).
  • You should aim at keeping units small (< 20 lines). Long units may become "bloaters", code that have increased to such gargantuan proportions that they are hard to work with.
Learn more...
Unit Size Overall
  • There are 325 units with 3,752 lines of code in units (66.7% of code).
    • 2 very long units (211 lines of code)
    • 8 long units (479 lines of code)
    • 34 medium size units (937 lines of code)
    • 65 small units (998 lines of code)
    • 216 very small units (1,127 lines of code)
5% | 12% | 24% | 26% | 30%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
py3% | 11% | 21% | 28% | 33%
cpp12% | 16% | 36% | 19% | 15%
h0% | 0% | 0% | 0% | 100%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
imagenet42% | 0% | 31% | 9% | 16%
cpp12% | 9% | 39% | 22% | 15%
fx0% | 27% | 18% | 16% | 37%
fast_neural_style0% | 43% | 8% | 20% | 26%
mnist0% | 50% | 0% | 41% | 7%
snli0% | 43% | 19% | 11% | 25%
distributed0% | 0% | 29% | 35% | 34%
reinforcement_learning0% | 0% | 54% | 13% | 31%
word_language_model0% | 0% | 17% | 39% | 42%
dcgan0% | 0% | 0% | 66% | 33%
vae0% | 0% | 0% | 57% | 42%
mnist_hogwild0% | 0% | 0% | 53% | 46%
super_resolution0% | 0% | 0% | 24% | 75%
time_sequence_prediction0% | 0% | 0% | 54% | 45%
regression0% | 0% | 0% | 0% | 100%
Alternative Visuals
Longest Units
Top 20 longest units
Unit# linesMcCabe index# params
def main_worker()
in imagenet/main.py
110 31 3
int main()
in cpp/dcgan/dcgan.cpp
101 7 2
int main()
in cpp/distributed/dist-mnist.cpp
78 7 2
def train()
in fast_neural_style/neural_style/neural_style.py
71 9 1
def main()
in fast_neural_style/neural_style/neural_style.py
60 5 0
def lower_to_elementwise_interpreter()
in fx/native_interpreter/use_interpreter.py
57 1 1
at::Tensor __call__()
in fx/native_interpreter/interpreter.cpp
56 13 1
def main()
in mnist/main.py
53 6 0
def nnc_compile()
in fx/nnc_compile.py
53 17 2
def get_args()
in snli/util.py
51 1 0
def run_worker()
in distributed/rpc/ddp_rpc/main.py
46 12 2
void basic_autograd_operations_example()
in cpp/autograd/autograd.cpp
43 2 0
void train()
in cpp/transfer-learning/main.cpp
36 4 5
def _run_trainer()
in distributed/rpc/ddp_rpc/main.py
34 9 2
def _run_trainer()
in distributed/rpc/rnn/main.py
34 5 0
auto main()
in cpp/mnist/mnist.cpp
34 3 0
def train()
in word_language_model/main.py
33 4 0
def vmap()
in fx/vmap.py
31 4 5
int main()
in cpp/custom-dataset/custom-dataset.cpp
31 4 0
def train()
in imagenet/main.py
31 7 6