AlDanial / cloc

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
GNU General Public License v2.0
19.75k stars 1.02k forks source link

Add option for file count only #708

Closed cosad3s closed 1 year ago

cosad3s commented 1 year ago

I needed something to only count files, classified by language. I like subroutines of cloc to identify languages but I was not satisfied by the performance drop caused by the line counting on big repositories (Which I do not need in my case). So I propose an option --only-count-files to skip line count.

Example on bash mirror repository https://github.com/bminor/bash :

❯ time ./cloc .
    1404 text files.
     587 unique files.                                          
     868 files ignored.

github.com/AlDanial/cloc v 1.97  T=0.73 s (801.4 files/s, 715967.8 lines/s)
---------------------------------------------------------------------------------------
Language                             files          blank        comment           code
---------------------------------------------------------------------------------------
PO File                                 39          25332          32315         170056
C                                      271          22627          21970         117193
HTML                                     3           4019             30          27309
Bourne Shell                            40           4513           3864          25686
Windows Module Definition               44           2676              9          15657
C/C++ Header                           113           2934           3591           8133
m4                                      40            663            829           7648
TeX                                      1            821           3462           6762
yacc                                     2            855            980           5411
Perl                                     2            535            834           4229
Text                                     4            363              0           1342
Bourne Again Shell                      16            177            327            769
Markdown                                 1             30              0            136
make                                     3             50             36            122
Assembly                                 2             11             20             48
awk                                      1              8             15             24
sed                                      2              0              0             16
TNSDL                                    3              0              0              5
---------------------------------------------------------------------------------------
SUM:                                   587          65614          68282         390546
---------------------------------------------------------------------------------------

real    0m0,821s
user    0m0,762s
sys     0m0,059s

❯ time ./cloc --only-count-files .
    1404 text files.
     587 unique files.                                          
     868 files ignored.

github.com/AlDanial/cloc v 1.97  T=0.05 s (10684.4 files/s, 0.0 lines/s)
---------------------------------------------------------------------------------------
Language                             files          blank        comment           code
---------------------------------------------------------------------------------------
Assembly                                 2              0              0              0
Bourne Again Shell                      16              0              0              0
Bourne Shell                            40              0              0              0
C                                      271              0              0              0
C/C++ Header                           113              0              0              0
HTML                                     3              0              0              0
Markdown                                 1              0              0              0
PO File                                 39              0              0              0
Perl                                     2              0              0              0
TNSDL                                    3              0              0              0
TeX                                      1              0              0              0
Text                                     4              0              0              0
Windows Module Definition               44              0              0              0
awk                                      1              0              0              0
m4                                      40              0              0              0
make                                     3              0              0              0
sed                                      2              0              0              0
yacc                                     2              0              0              0
---------------------------------------------------------------------------------------
SUM:                                   587              0              0              0
---------------------------------------------------------------------------------------

real    0m0,135s
user    0m0,109s
sys     0m0,024s
AlDanial commented 1 year ago

It's an interesting capability. I'll test & merge this coming weekend.

AlDanial commented 1 year ago

Future work: make --only-count-files work in diff mode also. Currently --only-count-files --diff counts lines too.