当前位置:网站首页>WC statistics are out of date, and every line of cloc code is valid
WC statistics are out of date, and every line of cloc code is valid
2022-06-23 11:46:00 【Li XXXI】
Context
We usually judge a programmer's skill or the size of a project by the amount of code , When reading the source code of a new project , You also need to know the amount of code , I have an expectation .
How to count the amount of code ?
Traditional practice
adopt find+wc Command complete
$ find . -name "*.go" | xargs wc -l
60 ./etcd/tutorial/distributed_lock.go
...
3491 total
Above , The statistics command displays all files , Altogether 3491 Line code . But the statistics here are too rough ,wc The statistical process will note 、 Blank lines and so on are counted as code statistics .
We should try more effective statistical methods .
Effective statistics cloc
cloc(Count Lines of Code[0]) It's a Perl Statistical tools of open source code for language development . Support for multiple platforms 、 Multilingual 、 Category counts the number of source code files in the target file or folder 、 Number of blank lines 、 Comment lines and code lines .
install
Support multiple installation methods , It includes almost all common installation methods .
npm install -g cloc # https://www.npmjs.com/package/cloc
sudo apt install cloc # Debian, Ubuntu
sudo yum install cloc # Red Hat, Fedora
sudo dnf install cloc # Fedora 22 or later
sudo pacman -S cloc # Arch
sudo emerge -av dev-util/cloc # Gentoo https://packages.gentoo.org/packages/dev-util/cloc
sudo apk add cloc # Alpine Linux
doas pkg_add cloc # OpenBSD
sudo pkg install cloc # FreeBSD
sudo port install cloc # macOS with MacPorts
brew install cloc # macOS with Homebrew
choco install cloc # Windows with Chocolatey
scoop install cloc # Windows with Scoop
cloc advantage ?
cloc Easy to use 、 Scalable and portable features :
Easy to install , Just download the package and run it . Support category statistics for multiple languages :Java、Go、Python、C etc. . Support category statistics of results in multiple formats : Pure text 、SQL、JSON、XML、YAML、 Comma separated values, etc . The number of files counted by category is supported 、 Number of blank lines 、 Comment lines and code lines .
Basic use
$ cloc ./ # Statistical table of contents
$ cloc perl-5.22.0.tar.gz # You can also directly count compressed packets
For front-end students , Statistical code often needs to ignore the largest node_modules And packaged dist file , Support filtering logic , Easy to use .
$ cloc $(git ls-files)
# or
$ cloc --vcs git
# Or filtration svn
$ cloc --vcs svn
Advanced usage
It's easy to use , The statistical results will count the blank lines of the source code according to the language classification 、 Comment lines and physical lines . As follows :
Count individual files
#$ cloc docker-compose-devcontainer.yml
1 text file.
1 unique file.
0 files ignored.
github.com/AlDanial/cloc v 1.92 T=0.01 s (140.6 files/s, 4919.9 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
YAML 1 3 1 31
-------------------------------------------------------------------------------
Statistics folder
$ cloc .
54 text files.
42 unique files.
14 files ignored.
github.com/AlDanial/cloc v 1.92 T=0.14 s (290.8 files/s, 22637.6 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Go 29 381 216 2468
Markdown 6 28 0 55
...
-------------------------------------------------------------------------------
SUM: 42 431 220 2618
-------------------------------------------------------------------------------
It also supports the adoption of --exclude-dir Parameter to filter out paths that are not counted in statistics
$ cloc . --exclude-dir=build
52 text files.
40 unique files.
14 files ignored.
github.com/AlDanial/cloc v 1.92 T=0.07 s (605.9 files/s, 48999.6 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Go 29 381 216 2468
Markdown 5 27 0 54
...
-------------------------------------------------------------------------------
SUM: 40 423 217 2595
-------------------------------------------------------------------------------
Press is also supported --by-file Parameter to filter the statistical results .
$ cloc . --by-file | head -n 10
54 text files.
42 unique files.
14 files ignored.
github.com/AlDanial/cloc v 1.92 T=0.03 s (1380.3 files/s, 107434.2 lines/s)
-----------------------------------------------------------------------------------------
File blank comment code
-----------------------------------------------------------------------------------------
./etcd/tutorial/demo.go 53 0 291
./etcd/simple_raft/raft_log.go 29 93 263
Count multiple subdirectories under the folder
$ for d in ./*/ ; do (cd "$d" && echo "$d" && cloc .); done
./go-bootcamp/
1474 text files.
1226 unique files.
540 files ignored.
github.com/AlDanial/cloc v 1.92 T=7.16 s (171.2 files/s, 118482.4 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
JavaScript 421 10606 84539 584311
...
-------------------------------------------------------------------------------
SUM: 1226 18182 100323 729998
-------------------------------------------------------------------------------
./html-bootcamp/
18 text files.
15 unique files.
5 files ignored.
github.com/AlDanial/cloc v 1.92 T=0.02 s (635.5 files/s, 9744.9 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
HTML 4 28 8 89
...
-------------------------------------------------------------------------------
SUM: 15 51 15 164
-------------------------------------------------------------------------------
./java-bootcamp/
3 text files.
1 unique file.
3 files ignored.
github.com/AlDanial/cloc v 1.92 T=0.01 s (104.8 files/s, 524.2 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Markdown 1 2 0 3
-------------------------------------------------------------------------------
More orders
$ cloc --help
Supported languages
$ cloc --show-lang
adopt docker function
$ docker run --rm -v $PWD:/tmp aldanial/cloc ./
above , That's all for today , Contains cloc Installation and use . Of course , Important content tends to be small , Very recommended docker Operation mode .
️️️ Every reader's love is the driving force of the author's progress ! I am a Thirty-one [1], Thank you for : Please thumb up 、 Ask for comment 、 Please forward , See you next time !
References
[0] Count Lines of Code: https://github.com/AlDanial/cloc [1] Thirty-one : http://www.lee31.cn/assets/image/ThirtyOneLee.jpeg
The articles
Introduction : from etcd The origin of the name , To install, deploy and use gestures How to see Python(PyScript) Can do browser front-end development language ? The depth of the summary , Take you around NVIDIA GPU Still living in the last era ,Etcd 3.0 Implementing distributed locks is so simple from 0 To 1, How to roll one with your bare hands Python Plug in system ? One stop machine learning business platform MLflow What about? ?
边栏推荐
- 电容参数哪里找!?
- 六维图剖析:中国建筑集团有限公司企业成长性分析
- 一张图解码 OpenCloudOS 社区开放日
- Tamidog | analysis of investor types and enterprise investment types
- navicat定时任务无效
- How to implement a distributed lock with redis
- Rancher 2.6 全新 Monitoring 快速入门
- Deveco device tool helps openharmony device development
- 汉源高科1路千兆光口转4路千兆以太网电口千兆1光4电光纤收发器
- Go 语言使用 MySQL 的常见故障分析和应对方法
猜你喜欢

DevEco Device Tool 助力OpenHarmony设备开发

華為雲如何實現實時音視頻全球低時延網絡架構

广播级E1转AES-EBU音频编解码器 E1转立体声音频卡侬头(XLR)编解码器

Meta称英安全法可能“扫描所有私人信息” 或侵犯隐私

2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案

单向链表实现--计数

汉源高科USB2.0光端机USB2.0光纤延长器USB2.0光纤传输器USB2.0接口转光纤

塔米狗 | 投资人类型分析以及企业投资类型分析

全国进入主汛期,交通运输部:不具备安全运行条件的线路坚决停运!

Redis 入门-第一篇-数据结构与对象-简单动态字符串(SDS)
随机推荐
The country has entered the main flood season. The Ministry of transport: the lines that do not meet the conditions for safe operation will be resolutely shut down!
Gradienttape of tensorflow2
Introduction to Huawei cloud maintenance and sharing exchange platform
At 14:00 today, 12 Chinese scholars started ICLR 2022
Rancher 2.6 new monitoring QuickStart
【零基础微信小程序】基于百度大脑人像分割的证件照换底色小程序实战开发
Three ways to learn at work
汉源高科USB3.0光端机USB工业触摸屏光端机USB3.0光纤延长器USB3.0光纤传输器
DevEco Device Tool 助力OpenHarmony設備開發
不止于观测|阿里云可观测套件正式发布
Voice data annotation tools and platforms
The simplest DIY actuator controller based on 51 single chip microcomputer
MySQL matches multiple values in one field
某问答社区App x-zse-96签名分析
Tensorrt notes (4) Modèle de segmentation du raisonnement
The simplest DIY actuator cluster control program based on 51 single chip microcomputer, pca9685, IIC and PTZ
Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online now?
电脑坏了,换了台电脑,装node环境的时候出了问题,报错URL not defined
How to implement a distributed lock with redis
Surprise! Amd acquires Xilinx with USD 35billion!