4 ms·
Slightly related, I only recently found out that the grep (BSD) included in macOS is way slower than the GNU equivalent that you can install from Homebrew. If y
by dewey 7y ago
Slightly related, I only recently found out that the grep (BSD) included in macOS is way slower than the GNU equivalent that you can install from Homebrew. If you ever had to work with big files and were confused why it's so much slower give it a try.
http://jlebar.com/2012/11/28/GNU_grep_is_10x_faster_than_Mac_grep.html http://jlebar.com/2012/11/28/GNU_grep_is_10x_faster_than_Mac...
- teraflop 7y agoRelated, from 2010: "why GNU grep is fast" (https://lists.freebsd.org/pipermail/freebsd-current/2010-August/019310.html https://lists.freebsd.org/pipermail/freebsd-current/2010-Aug...)
- asicsp 7y agoI've also seen questions on unix.stackexchange like [1][2] that BSD grep has been buggy for some common usecases [1] https://unix.stackexchange.com/questions/398223/grep-strange-behaviour-with-single-letter-words https://unix.stackexchange.com/questions/398223/grep-strange... [2] https://unix.stackexchange.com/questions/352977/why-does-this-bsd-grep-result-differ-from-gnu-grep https://unix.stackexchange.com/questions/352977/why-does-thi...
- opencl 7y agoAnd ripgrep is quite a lot faster than GNU grep[1], especially if you need unicode support. [1] https://blog.burntsushi.net/ripgrep/ https://blog.burntsushi.net/ripgrep/
- dewey 7y agoIt depends, I benchmarked all of the usual suspects (fgrep, GNU grep, BSD grep, ripgrep, sift grep) on the same 30GB line separated JSON file last week and GNU grep was the fastest one. I didn't have a scientific testing setup though. I just ran them one by one like this: time cat title_complete_json.txt | grep tt9184994 >> result
- Scarbutt 7y agoThe infamous "useless use of cat"
- adrusi 7y agoThat's relevant in some scripts, where unnecessary forks might actually add up to some meaningful resource usage. Not relevant when typed at a tty.
- nsajko 7y agoTo clarify, it would have been prettier (conceptually less clunky and shorter) to run this: time grep tt9184994 < title_complete_json.txt >> result
- catucia 7y agogrep takes a file directly, so this could simply be: time grep tt9184994 title_complete_json.txt >> result
- hyper_reality 7y agoIt annoys me whenever somebody brings this up. People do this because it's easier to modify commands at the end of your prompt than near the beginning. Especially in this case, where the grandparent wants to quickly switch between benchmarking grep, ripgrep etc. Not useless at all.
- naniwaduni 7y agoThough a neat thing to know is that redirections can appear anywhere on the line in Bourneish shells: time < title_complete_json.txt grep tt9184994 As it happens, when benchmarking grep-like tools on large files, this is actually somewhat likely to make a significant difference since the "useless" use of cat actually forces the file to be read sequentially as a stream (because it's piped through), while a process receiving a file on standard input can treat it as a file and e.g. mmap it.
- s_dev 7y agoThis is true of quite a few tools. https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/ https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-c...