1. 安装
sudo apt-get install cloc
其中 cloc
使用 Perl
实现;而 scc
是 Go
实现的,项目地址:https://github.com/boyter/scc
这两个工具的功能类似,但也会有差别。不过 scc
速度快很多。
scc
,又叫做 Sloc
、Cloc
和 Code
,即取这三个单词的首字母:SCC
。scc
是一个非常快速准确的代码计数器,具有复杂度计算和 COCOMO
估计,用纯 Go
编写。
scc
允许查看代码使用的每种编程语言、行数、注释、文件等。这是一个非常快速且有用的工具。大部分语言 scc
都支持,通过 scc --languages
查看支持的语言,目前有 201 种。
2. 使用
进入代码所在目录直接执行以下命令
$ cloc .
8 text files.
8 unique files.
2 files ignored.
github.com/AlDanial/cloc v 1.74 T=0.09 s (67.4 files/s, 2437.7 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
XML 4 0 0 105
Python 2 23 5 84
-------------------------------------------------------------------------------
SUM: 6 23 5 189
-------------------------------------------------------------------------------
或者
$ scc .
───────────────────────────────────────────────────────────────────────────────
Language Files Lines Blanks Comments Code Complexity
───────────────────────────────────────────────────────────────────────────────
XML 3 18 0 0 18 0
Python 2 112 23 5 84 20
gitignore 1 3 0 1 2 0
───────────────────────────────────────────────────────────────────────────────
Total 6 133 23 6 104 20
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $2,508
Estimated Schedule Effort (organic) 1.413242 months
Estimated People Required (organic) 0.157717
───────────────────────────────────────────────────────────────────────────────
Processed 4265 bytes, 0.004 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
$