万众期待的 ripgrep 已经上线。
grep
ripgrep
ripgrep 非常出色,其 GitHub 仓库已经接近 14000 个星标。仓库地址为:https://www.php.cn/link/add6ab8551d16aa6fbe68c50f740cc94。
ripgrep 超越 grep 的第一个优势是其跨平台特性,不再排斥 Windows 用户,Windows、Linux、macOS 的使用效果完全一致。
第二个优势是更美观的输出。
当然,美观这个问题见仁见智。
第三个优势是其强大的性能。
我们来实际测试一下。
对比 1:
搜索 Linux 内核源文件(在执行完
make defconfig && make -j8
rg -n -w '[A-Z]+_SUSPEND'
450
0.106s
git grep
LC_ALL=C git grep -E -n -w '[A-Z]+_SUSPEND'
450
0.553s
The Silver Searcher
ag -w '[A-Z]+_SUSPEND'
450
0.589s
git grep (Unicode)
LC_ALL=en_US.UTF-8 git grep -E -n -w '[A-Z]+_SUSPEND'
450
2.266s
sift
sift --git -n -w '[A-Z]+_SUSPEND'
450
3.505s
ack
ack -w '[A-Z]+_SUSPEND'
1878
6.823s
The Platinum Searcher
pt -w -e '[A-Z]+_SUSPEND'
450
14.208s
(上图中,
ack
对比 2:
再次搜索 Linux 内核源代码,搜索范围和参数有所变化。
rg -L -u -tc -n -w '[A-Z]+_SUSPEND'
404
0.079s
ucg
ucg --type=cc -w '[A-Z]+_SUSPEND'
390
0.163s
GNU grep
egrep -R -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND'
404
0.611s
(
ucg
对比 3:
搜索一个约 9.3G 的大文件。
rg -w 'Sherlock [A-Z]\w+'
5268
2.108s
GNU grep
LC_ALL=C egrep -w 'Sherlock [A-Z]\w+'
5268
7.014s
为什么推荐使用 ripgrep?
因为它涵盖了其他类似搜索工具的大部分功能,并且速度更快。ripgrep 会识别 .gitignore 文件并忽略其中指定的文件和目录。默认情况下不会搜索隐藏文件和目录。默认情况下不会搜索二进制文件。ripgrep 可以指定搜索某些类型的文件。例如,
rg -tpy foo
rg -Tjs foo
代码语言:javascript代码运行次数:0运行复制```javascript $ cargo install ripgrep
<pre class="brush:php;toolbar:false;"><p>安装使用吧。
以上就是【每日一库】ripgrep - grep的替代者的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号