Comments (3)
GNU grep can tell that its output is redirected to /dev/null
and because of that it exits after the first match. (It still needs to use the exit code to report whether there was a match at all, but that's it.) If you send the output through cat
then it cannot perform that optimization and ends up slightly slower than ripgrep:
$ hyperfine 'rg system rockyou.txt | cat' 'grep system rockyou.txt | cat'
Benchmark #1: rg system rockyou.txt | cat
Time (mean ± σ): 50.4 ms ± 10.8 ms [User: 37.6 ms, System: 14.2 ms]
Range (min … max): 43.0 ms … 84.6 ms 34 runs
Benchmark #2: grep system rockyou.txt | cat
Time (mean ± σ): 71.8 ms ± 13.3 ms [User: 54.3 ms, System: 18.9 ms]
Range (min … max): 60.4 ms … 97.5 ms 36 runs
Summary
'rg system rockyou.txt | cat' ran
1.42 ± 0.40 times faster than 'grep system rockyou.txt | cat'
from ripgrep.
Interesting, thanks for the explanation! Seems like I never looked at the execution time when getting an output...
from ripgrep.
Yeah @blyxxyz has it right. For hyperfine specifically, you can pass --output=pipe
instead of adding | cat
.
I have specifically avoided the "detect /dev/null
and automatically enable -q/--quiet
" optimization that GNU grep does. ripgrep could do it. It isn't hard to do. It just always seemed a little weird to me.
For simple literal searches like this, ripgrep should pretty much always be faster. ripgrep's substring search should be very nearly strictly superior to GNU grep's. If you can find a non-pathological case where GNU grep is noticeably faster (on x86-64 or aarch64) for real, I'd love to see it.
from ripgrep.
Related Issues (20)
- multiline search regex wildcard not expanding HOT 1
- Precompiled binary for powerpc64le HOT 1
- Add Vuejs as a file list to type-list HOT 1
- zero or more quantifier does not work HOT 1
- Inconsistent behavior with negation pattern in `.gitignore` HOT 8
- compiling with simd-accel feature is broken due to removal of stdsimd feature in nightly breaking the packed_simd crate HOT 1
- File named `.config` is ignored for no reason HOT 1
- Process substitution search path behavior change in 14.0.0
- [feature] Line masking (ignoring lines or part of lines in matching but displayed in output) HOT 3
- Provide Statically Compiled Binaries for (aarch64|arm64) Linux HOT 1
- Include regex syntax in man page HOT 1
- Include ---no-ignore-files in --unrestricted option? HOT 1
- ripgrep mis-parses `*[\<\>\:\"\/\\\|\?\*]*` in `.gitignore` HOT 2
- Incorrect application of ignore rule with single glob in nested HOT 1
- Since nightly-2024-02-06 , could not compile with --features 'simd-accel' HOT 4
- rg allocates too much memory with: `rg --files --ignore-file ~/.ultimate-gitignore` HOT 2
- Repo HOT 1
- When i using rg to find file's type of rust, it doesn't work. HOT 1
- Typo in help description for --vimgrep option: "im" instead of "in" HOT 1
- rg spins in a nanosleep loop when one thread is blocked on a fifo
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripgrep.