Today, when searching online for grep usage, I suddenly see other more efficient ways of searching. Of course they should not exist so-called who better. The key is to use different search commands on different occasions to improve efficiency. In fact, because they have not used the other two methods, at present can not jump to conclusions. That is to refer to the introduction of the Internet, the initial experience is just, and so on a period of time, have their own experience to say it.
These three search commands can be installed under the terminal using the command line. Where grep is released with Ubuntu, it has itself. The other two, we only need to operate the ACK at the Terminal AG, the system will give us prompt installation package and installation command, we just need to follow the instructions to do it. As for the use of the method, or need to find out later, you can rely on the help command.
Now, I mainly want to based on the introduction of the Internet to study the three commands in the large operating directory of the execution efficiency. The authentication environment is in the ~ directory, and the operation is to find where all the Java strings appear. The validation results are as follows
1.ag
Execute command
Time AG Java
Execution results (partial)
Download/vim-backup/vim/zhangshuli.vim/plugin/Taglist.vim413: Let s:tlist_def_html_settings ='html;a:anchor;f:javascript function'415:"Java language416: Let s:tlist_def_java_settings ='Java;p:package;c:class;i:interface;' .419:"JavaScript Language420: Let s:tlist_def_javascript_settings ='javascript;f:function'Download/vim-backup/vim/ZHANGSHULI.VIMRC290: Autocmd bufnewfile,bufread *.java Set formatprg=Astyle324:"For Java & C + +
Execution time
Real 1m14.938suser 0m2.410ssys 0m2.757s
2.ack
Execute command
time ack-grep java
Execution results (partial)
Download/vim-backup/vim/zhangshuli.vim/plugin/Taglist.vim413: Let s:tlist_def_html_settings ='html;a:anchor;f:javascript function'415:"Java language416: Let s:tlist_def_java_settings ='Java;p:package;c:class;i:interface;' .419:"JavaScript Language420: Let s:tlist_def_javascript_settings ='javascript;f:function'Download/vim-backup/vim/ZHANGSHULI.VIMRC290: Autocmd bufnewfile,bufread *.java Set formatprg=Astyle324:"For Java & C + +
Execution time
Real 1m6.235suser 0m18.153ssys 0m1.766s
3.grep
Execute command
Time grep -rn java.
Execution results (partial)
./Download/vim-backup/vim/zhangshuli.vim/plugin/taglist.vim:415:"Java language./Download/vim-backup/vim/zhangshuli.vim/plugin/taglist.vim:416: Let s:tlist_def_java_settings ='Java;p:package;c:class;i:interface;' ../download/vim-backup/vim/zhangshuli.vim/plugin/taglist.vim:419:"JavaScript Language./Download/vim-backup/vim/zhangshuli.vim/plugin/taglist.vim:420: Let s:tlist_def_javascript_settings ='javascript;f:function'./download/VIM-BACKUP/VIM/ZHANGSHULI.VIMRC:290: Autocmd bufnewfile,bufread *.java Set formatprg=Astyle./download/VIM-BACKUP/VIM/ZHANGSHULI.VIMRC:324:"For Java & C + +
Execution time
Real 2m20.380suser 0m6.482ssys 0m3.779s
Conclusion:
It seems that the ACK is almost as efficient as the AG execution (the experiments that others do online, the AG is much better than the ACK block, don't know why), and their results show more clarity.
Grep's a little bit slow.
After the operation of the source code, in contrast to the pros and cons of these three commands
In addition, we can also use the AG as a vim plug-in, the specific method with the ordinary plug-in no difference, you just need to ag.vim plug-in corresponding files of the vim corresponding file directory on the line.
Https://github.com/rking/ag.vim
grep, ACK, ag-search function