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
time grep tt9184994 < title_complete_json.txt >> result
time grep tt9184994 title_complete_json.txt >> result
Not useless at all.
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.Thanks for your tip, it's clearly the best of both worlds for this purpose.
$ time rg QZQZQZQZ < subtitles.en.txt
real 1.842
user 0.552
sys 1.287
maxmem 9 MB
faults 0
$ time rg QZQZQZQZ subtitles.en.txt
real 1.210
user 0.776
sys 0.433
maxmem 9510 MB
faults 0
(See my other comments in this thread for where to get subtitles.en.txt.)In pretty much any case involving more complicated queries and/or unicode I have found rg to be the fastest by a very wide margin. Also if you're searching multiple files rg is multithreaded by default without having to pass through something like xargs or parallel. If you're just searching for an ASCII string literal in a single file rg probably gets slowed down by its UTF-8 validation.
> If you're just searching for an ASCII string literal in a single file rg probably gets slowed down by its UTF-8 validation.
This is most definitely wrong. Firstly, ripgrep doesn't do any UTF-8 validation. That would make it much much slower. Secondly, searching a simple literal is one of the cases where ripgrep should actually do better than GNU grep in many cases. This is because of the slightly smarter way in which ripgrep keeps its vectorized loop active more often than GNU grep does by trying to search rarer bytes. I talk about this quite a bit here, which even includes a benchmark where I measured ripgrep at 2x the speed of GNU grep for a simple literal search: https://blog.burntsushi.net/ripgrep/#subtitles-literal
Anyone can try this for themselves:
$ cd /tmp
$ curl 'https://object.pouta.csc.fi/OPUS-OpenSubtitles/v2016/mono/en.txt.gz' | gzip -cd > subtitles.en.txt
$ pv < subtitles.en.txt > /dev/null
9.28GiB 0:00:01 [4.89GiB/s] [======================================================================================================================================================>] 100%
$ time grep ZQZQZQZQ < subtitles.en.txt
real 8.713
user 7.495
sys 1.212
maxmem 9 MB
faults 0
$ time rg ZQZQZQZQ < subtitles.en.txt
real 1.857
user 0.573
sys 1.282
maxmem 9 MB
faults 0
On my system, /tmp is a ramdisk, so this doesn't factor in I/O. If you look up this thread, you'll note that someone was trying to search a 30GB file. Unless that person could fit that file into memory, it's very likely that they were just measuring the I/O bandwidth of their machine.I would try to get as small an output as possible, and not hit the file system at all, for example by using
time cat title_complete_json.txt | grep tt9184994 | grep -v tt9184994> ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern
I'm not sure if many other people would jump to similar conclusions. So the readme might not really need a revision.