技术控

    今日:60| 主题:49101
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Grep is Losing Its Grip

[复制链接]
把持不住 发表于 昨天 15:35
30 0

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Grep is the ubiquitous command line tool for finding lines in files that match a pattern. Originally invented by computer science luminary Ken Thompson in November 1974, it was originally developed for the Unix operating system, but is available today, in some form or another, on almost all systems. Grep has been the defacto standard for programmers everywhere to find stuff in files. However, as time and technology has advanced, the sheer size and number of files has grown at a rapid rate. A good example is the source code for the linux kernel which at version 1.0 in 1994 consisted of 170,000 lines of code, and as of version 4.8 is now over 22M lines of code .
   
Grep is Losing Its Grip-1 (technology,available,developed,computer,invented)

  As you can well imagine, grep on most systems is fairly dated when taking modern multicore processors into account. Grep uses a single thread to do its work, and performance clearly suffers over large filesets even with our modern powerful systems.
  Now you can break up a grep in a variety of ways in order to inject some potential concurrency upside for your search. I say “potential” as there are many factors involved including your search tree, hardware, IO bottlenecks, etc. Here is one way:
  [code]% find . -type f -print0 | xargs -0 -P [number_of_processes] grep [pattern][/code]   This gets the job done, but surely we can more productive than this for our everyday development. In fact, why don’t we have a tool that is both fast, concurrently capable, and tailored to the needs of developers? In fact, we do! In the Perl world we have Andy Lester’s excellent ack! This works on any Perl (orActivePerl of course!) A great benefit for developers, it ignores your coredump files, binaries, backup and code repository files. It also has the advantage of using Perl's regular expressions which have always been top notch amongst languages. Typical usage:
  [code]% ack [pattern][/code]  But I suggest you try the following:
  [code]% ack --thppt[/code]  Ack, why didn’t you specify the directory to search from? Well in order to be maximally productive, it defaults to recursive directory search from the current working directory! This is perfect when searching your code trees. However, ack has a performance weakness...it still isn’t concurrent out-of-the-box (but could be used in a similar way like in the above grep example).
   This brings us to Geoff Greer’s feature-rich, ack-inspired, The Silver Searcher (great name!). This fantastic tool claims to be an order of magnitude faster than ack due to its implementation in C and use of pthreads to provide concurrency among many other improvements. Now, instead of “ack”, we can just type the clever “ag”, which is the periodic table chemical symbol for silver:
  [code]% ag [pattern][/code]  It also ignores files you normally don't want to be searching in your codebase and looks for .gitignore and .hgignore files and you can even specify your own .ignore file.
   Lastly, we’ve been doing a lot of work with the Go language here at ActiveState. We are working towards our upcomingActiveGo™ distribution (link to signup page) and I would be remiss if I didn’t mention another fantastic grep-like tool built out of Go that is performance equivalent to ag.
   I discovered this when Dave Cheney gave a shoutout to Monochromegane’s The Platinum Searcher on episode 16 of the stellar Go Time podcast . This solution is coded in Go and makes fantastic use of Go’s built in concurrency support to obtain its solid performance. Like ack and ag it also ignores code repo files you don’t want to search through. Imitation is clearly the highest form of flattery. Installation is a snap as you can just grab the binary you need for mac, windows or linux and put it in your path and you’ve got another great grep-like tool. Basic usage is the same as The Silver Searcher, but with platinum’s chemical symbol instead:
  [code]% pt [pattern][/code]  If you’re still working with your system installed grep, I highly recommend you move to a higher performance and developer oriented tool such as the Silver or Platinum Searchers!
  Having opened the article mentioning Ken Thompson, and his invention of grep, we’ve come full circle...Ken Thompson is one of the co-creators of Go a mere 35 years later! Happy searching!
友荐云推荐




上一篇:TiKV 的 MVCC(Multi-Version Concurrency Control)机制
下一篇:浅入浅出 Android 安全:第三章 Android 本地用户空间层安全
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表