Live data from Hacker News

Don’t underestimate grep-based code scanning

littlemaninmyhead.wordpress.com

11–20 of 122 posts

Re: Don’t underestimate grep-based code scanning

#12
post #8

Earlier quoted context omitted.

Grep is really fast at that at the actual search (gnu grep at least), the gain there is mostly that "smarter" tools will ignore e.g. VCS data or binary files by default whereas grep will trawl through your PNGs and git packfiles.

Explanation from the original author on why GNU grep is fast: https://lists.freebsd.org/pipermail/freebsd-current/2010-Aug... Excerpt: "The result of this is that, in the limit, GNU grep averages fewer than 3 x86 instructions executed for each input byte it actually looks at (and it skips many bytes entirely)."

There's also this bit: https://ridiculousfish.com/blog/posts/old-age-and-treachery....

However note https://news.ycombinator.com/item?id=19522987

> It does not. ripgrep does not use Boyer-Moore in most searches.

> In particular, the advice in [the freebsd mailing list post] is generally out of date.

although the out of date bits are really the Boyer-Moore ones: https://lobste.rs/s/ycydmd

> much of Mike Haertel’s advice in this post is still good. The bits about literal scanning, avoiding searching line-by-line, and paying attention to your input handling are on the money.

> But the stuff about Boyer-Moore is outdated.

Re: Don’t underestimate grep-based code scanning

#13
post #6

Earlier quoted context omitted.

Why is it better than grep?

It's way faster, which is great when you're working with big repos. It's designed for recursively searching through a lot of files.

However fast it is, it's going to have a tough time beating /usr/bin/fgrep.

Re: Don’t underestimate grep-based code scanning

#14
post #2

Just a small note that I would highgly recommend ripgrep[0] over standard grep. It's another modern tool that has been created by leveraging Rust and it's from BurntSushi[1] who is excellent. 0: https://github.com/BurntSushi/ripgrep 1. https://github.com/BurntSushi

This program re-invented find + egrep.

It is written in Rust which isn't available on anything other than Linux, OS X and Windows.

I'll just stick to /usr/bin/find and /usr/bin/egrep programs. That works just fine without having to port Rust before trying to build a re-invention of find and egrep.

Re: Don’t underestimate grep-based code scanning

#15
post #14
post #2

Just a small note that I would highgly recommend ripgrep[0] over standard grep. It's another modern tool that has been created by leveraging Rust and it's from BurntSushi[1] who is excellent. 0: https://github.com/BurntSushi/ripgrep 1. https://github.com/BurntSushi

This program re-invented find + egrep. It is written in Rust which isn't available on anything other than Linux, OS X and Windows. I'll just stick to /usr/bin/find and /usr/bin/egrep programs. That works just fine without having to port Rust before trying to build a re-invention of find and egrep.

It "reinvented" it and made it dramatically faster. Rust is also available on FreeBSD. I don't think you actually need Rust to run ripgrep. It's not like it's an interpreted language.

Re: Don’t underestimate grep-based code scanning

#16
post #13
post #6

Earlier quoted context omitted.

It's way faster, which is great when you're working with big repos. It's designed for recursively searching through a lot of files.

However fast it is, it's going to have a tough time beating /usr/bin/fgrep.

fgrep -r takes about six times longer than rg on the repository that I'm currently working on.

Re: Don’t underestimate grep-based code scanning

#17
post #15
post #14

Earlier quoted context omitted.

This program re-invented find + egrep. It is written in Rust which isn't available on anything other than Linux, OS X and Windows. I'll just stick to /usr/bin/find and /usr/bin/egrep programs. That works just fine without having to port Rust before trying to build a re-invention of find and egrep.

It "reinvented" it and made it dramatically faster. Rust is also available on FreeBSD. I don't think you actually need Rust to run ripgrep. It's not like it's an interpreted language.

Since when do FreeBSD executables run on the illumos family of operating systems, as far as I know, there is no freebsd-branded zone yet in illumos?

Dramatically faster? Is there any scientific evidence to that?

If it were me, I wouldn't rush to make assumptions.

Re: Don’t underestimate grep-based code scanning

#20
post #17
post #15

Earlier quoted context omitted.

It "reinvented" it and made it dramatically faster. Rust is also available on FreeBSD. I don't think you actually need Rust to run ripgrep. It's not like it's an interpreted language.

Since when do FreeBSD executables run on the illumos family of operating systems, as far as I know, there is no freebsd-branded zone yet in illumos? Dramatically faster? Is there any scientific evidence to that? If it were me, I wouldn't rush to make assumptions.

I tried it and it's much faster for me. The author did some benchmarks. I'm not about to publish a paper.

I also never said anything about Illumos.

Post reply on HN