3 ms·
I'm the author of ag. Sift has been mentioned to me a few times, and I finally felt the need to comment on it. Sift is a neat tool and I hope people get a lot
by ggreer 11y ago
I'm the author of ag. Sift has been mentioned to me a few times, and I finally felt the need to comment on it.
Sift is a neat tool and I hope people get a lot of use out of it. That said, I don't think the chosen benchmarks are indicative of real-world performance. For example, I just downloaded the latest Linux kernel source, built it, and ran sift and ag on it. This is on a Core i7 4770K with 32GB of RAM and an Intel 330 series SSD. Times are medians of 5 runs each. FS cache was hot.
ggreer@lithium:~/Downloads/linux-4.3% du -sh
12G .
ggreer@lithium:~/Downloads/linux-4.3% time ~/code/sift/sift -n --group line_number
...
~/code/sift/sift -n --group line_number 10.03s user 1.59s system 625% cpu 1.856 total
ggreer@lithium:~/Downloads/linux-4.3% time ag line_number
...
ag line_number 0.68s user 1.03s system 459% cpu 0.371 total
0.37s vs 1.86s. You can see the output of both commands in my gist[1]. Ag obeys .gitignore/hgignore/etc by default, so it shows fewer results.[2] Since sift can't search files with greater than 2^18 characters between newlines, it prints out quite a few error messages. This typically happens with binary files and minified css/js.
You may be wondering why I added command line options to sift. They are to enable grouping and line numbers, making the output similar to ag. This may seem cosmetic, but it actually affects performance. Displaying line numbers means you have to count line numbers. That requires reading the entire matching file and adding up the newlines.
One last bit of benchmarking: If I tell ag to do an unrestricted search (meaning both ag and sift search the same files) and I tell sift to format its output like ag (meaning both count line numbers), the results are much closer. Sift takes 1.85 seconds. Ag takes 1.60 seconds. But unlike sift, ag doesn't bail on big files without newlines. It dutifully reports all the matching .o files.
Really though, sift and ag are trying to solve different problems. I designed ag to be a code searching tool. From what I can tell, sift is meant to be more of a grep replacement. Instead of worrying so much about which one is faster, use the right tool for the job.
1. https://gist.github.com/ggreer/96ed22bab57d1e791b9d https://gist.github.com/ggreer/96ed22bab57d1e791b9d
2. I consider this a feature. The goal of ag is to find what you're looking for, not to show everything remotely related to what you're looking for. If the default search doesn't find anything, you can quickly add the "-a" option.
- Touche 11y agoI love ag and use it daily. One problem I constantly run into is searching for something and getting minified JavaScript in the results which is unreadable and eats up all scrollable space in my terminal. I'd like to ignore all files with super-long lines in them, any options for this sort of problem?
- lancefisher 11y agoIt doesn't ignore long lines, but you can use the .agingore file to ignore *.min.js, node_modules, and other patterns. https://github.com/ggreer/the_silver_searcher/wiki/Advanced-Usage https://github.com/ggreer/the_silver_searcher/wiki/Advanced-...
- mborch 11y agoJust add these to your .gitignore/.hgignore/.agignore file.
- Touche 11y agoThat's not practical, I don't know the name of every minified file as there could be a lot of them packaged with dependencies.
- z1mm32m4n 11y agoWow, I had never thought about that. I've run into issues with minified JavaScript files as well, but never really thought about how much it annoyed me. To "ignore" super-long lines, we can just use a Unix filter: ag --color --group <pattern> | cut -c -100 the --color and --group force ag to not change the output just because we're piping the output to something that isn't a tty. The cut command simply clamps all lines at 100 chars; feel free to change this length. This is pretty long, so we could write a wrapper function or something: agc() { ag --color --group $@ | cut -c -100 } Stick it in your zshrc and you're good to go.
- Touche 11y agoPerfect, thank you.