uokadaの見逃し三振は嫌いです

ここで述べられていることは私の個人的な意見に基づくものであり、私が所属する組織には一切の関係はありません。

clocとlocを試してみた。

clocとは?

Perl製のコードの行数を計測するツールです。
GitHub - AlDanial/cloc: cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

locとは?

clocにインスパイアされた(?)Rust製のコードの行数を計測するツールです。
GitHub - cgag/loc: Count lines of code quickly.

clocのインストール

早速、clocを試してみましょう。 今回はbrweからインストールしてみます。

% brew install cloc

今回はdjangoリポジトリを使ってパフォーマンスなどを見ていきます。

% git clone https://github.com/django/django.git
Cloning into 'django'...
remote: Counting objects: 398103, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 398103 (delta 0), reused 0 (delta 0), pack-reused 398101
Receiving objects: 100% (398103/398103), 163.06 MiB | 2.83 MiB/s, done.
Resolving deltas: 100% (289580/289580), done.
Checking out files: 100% (5766/5766), done.

% cloc django
   4005 text files.
   3902 unique files.
   1149 files ignored.

github.com/AlDanial/cloc v 1.74  T=41.37 s (81.9 files/s, 15448.0 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Python                        1883          50083          48320         216702
PO File                       1136          70500           9752         213272
JavaScript                      45           2938           3450          13531
HTML                           234            521             19           4414
CSS                             30            656            115           2755
JSON                            43              3              0           1415
XML                             14              0              2            207
DOS Batch                        1             23              1            165
make                             2             30              7            134
INI                              1              7              0             59
Bourne Shell                     1              4              7             17
-------------------------------------------------------------------------------
SUM:                          3390         124765          61673         452671
-------------------------------------------------------------------------------
>>> elapsed time 41s

コマンドの完了までに41秒かかってしまいました。 3300ファイルもあるとなかなか時間がかかりますね。

locのインストール

次に、locを実行してみましょう。今回はwgetgithubから取得してきます。

% wget https://github.com/cgag/loc/releases/download/v0.3.4/loc-v0.3.4-x86_64-apple-darwin.tar.gz
% tar zxvf loc-v0.3.4-x86_64-apple-darwin.tar.gz

% ./loc django
--------------------------------------------------------------------------------
Language             Files        Lines        Blank      Comment         Code
--------------------------------------------------------------------------------
Python                2419       315559        50191        19358       246010
Plain Text             436       127392        34876            0        92516
JavaScript              45        19919         2938         3451        13530
HTML                   302         5029          523           19         4487
CSS                     31         3526          656          115         2755
JSON                    44         1427            3            0         1424
XML                     15          220            0            2          218
Batch                    1          189           23            1          165
Makefile                 2          171           30            7          134
INI                      1           66            7            0           59
reStructuredText         3           85           26            0           59
Autoconf                 1           17            0            0           17
Bourne Shell             1           28            4            8           16
ASP.NET                  2            2            0            0            2
--------------------------------------------------------------------------------
Total                 3303       473630        89277        22961       361392
--------------------------------------------------------------------------------

locの方は実行時間1秒程度で完了しました。

ただ、clocの結果とかなり違うのでどっちが正確な結果なのか判断するのは難しいです。。。
実績でclocの方の結果が正確だろうというのが自分の予想です。

正確性のclocと早さのlocといった認識で使い分けをするのが良いのかなというところです。

Link