Live data from Hacker News

Why GNU grep is fast (2010)

lists.freebsd.org

101–110 of 133 posts

Re: Why GNU grep is fast (2010)

#101
post #60

I'm actually more familiar with the KMP algorithm than BM. So I looked it up to see what the difference was: The classic Boyer-Moore algorithm suffers from the phenomenon that it tends not to work so efficiently on small alphabets like DNA. The skip distance tends to stop growing with the pattern length because substrings re-occur frequently. By remembering more of what has already been matched, one can get larger sk…

Couldn't you speed up a small-alphabet search by considering pairs or triplets of characters so you have N^2 or N^3 glyphs instead of N characters (so, going from 4 characters to 16 cgaracters to 64 characters)?

Re: Why GNU grep is fast (2010)

#102

The fastest programs are the ones that don't prepare themselves to do something and then don't do that thing. Another way to say just do one thing well.

The fastest programs return 0 immediately and don't do shit.

Technically the fastest non-portable program returns whatever was in eax upon call if I remember right.

Re: Why GNU grep is fast (2010)

#103
post #45

The inverse is this...what is modern software doing that makes them so slow?

Portability and maintainability, if you want to boil it down to the core. The speed of gnu grep probably isn't portable since it relies on the kernel to do certain things in a cooperative manner, and it certainly won't be easy to maintain while staying fast.

I see the same in some of our software. One of our senior is rolling out a number of very, very fast collections based on compare-and-swap-operations, but you always end up thinking an hour or two about five lines of code. Most problem domains don't need this kind of performance, so most software teams don't pay the maintenance price and I think they are correct about that judgement call.

Re: Why GNU grep is fast (2010)

#104
post #103
post #45

The inverse is this...what is modern software doing that makes them so slow?

Portability and maintainability, if you want to boil it down to the core. The speed of gnu grep probably isn't portable since it relies on the kernel to do certain things in a cooperative manner, and it certainly won't be easy to maintain while staying fast. I see the same in some of our software. One of our senior is rolling out a number of very, very fast collections based on compare-and-swap-operations, but you al…

Part of the performance is algorithmic. Mixing Boyer-Moore and regexes isn't elementary. However, the knowledge is available for anyone keen to apply it.

Re: Why GNU grep is fast (2010)

#105
post #65

Earlier quoted context omitted.

There is a third one, at low level: make it do something else. For example, programmer requests a multiplication, compiler generates a shift; programmer requests a division, compiler generates a multiplication; programmer specifies a switch, compiler generates a jump table.

I'd argue that's just a variation of doing less, in the same way that e.g. vectorization is a variation of parallelism.

The same concept applies to transportation. How to get around faster: take shorter routes, and take all the stuff you're going to need on the first trip.

Re: Why GNU grep is fast (2010)

#106

Earlier quoted context omitted.

I think Kent was being sarcastic - his point is that it's rather pointless to optimize until the system is producing correct results. He's also famous for the "Make it work, make it right, make it fast" quote.

'Compile, conform, perform'

Where is this from?

Re: Why GNU grep is fast (2010)

#107
post #90
post #74

Earlier quoted context omitted.

$ touch foo $ chmod +x foo $ ./foo $ echo $? 0

For me, the trivial C program appears to run faster than the empty file: $ touch empty $ chmod +x empty $ time ./empty real 0m0.002s user 0m0.000s sys 0m0.000s $ echo "int main(){return 0;}" > trivial.c $ gcc trivial.c -o trivial $ time ./trivial real 0m0.001s user 0m0.000s sys 0m0.000s Timing results are consistent over several repetitions (provided everything's in cache from disk). Linux x86_64. `mov` takes ten tho…

I get the same results:

    $ touch empty

    $ chmod +x empty 

    $ time ./empty 

        real    0m0.005s
        user    0m0.001s
        sys     0m0.001s

    $ echo "int main(){return 0;}" > trivial.c

    $ gcc trivial.c -o trivial

    $ time ./trivial

        real    0m0.002s
        user    0m0.001s
        sys     0m0.002s

Re: Why GNU grep is fast (2010)

#108
post #88

Impressive, but if the goal is for BSD to have a faster grep then clearly the solution is to use GNU grep instead of rolling their own redundant and inferior clone.

presumably GNU grep is GPL and incompatible with their BSD license

The GNU GPL is perfectly compatible with their BSD license... :]

It's just that the end result is then restricted by the GPL, and they don't want that.

Re: Why GNU grep is fast (2010)

#109
post #88

Impressive, but if the goal is for BSD to have a faster grep then clearly the solution is to use GNU grep instead of rolling their own redundant and inferior clone.

presumably GNU grep is GPL and incompatible with their BSD license

Is grep part of the BSD base system?

Re: Why GNU grep is fast (2010)

#110
post #53

Earlier quoted context omitted.

[deleted]

I think Kent was being sarcastic - his point is that it's rather pointless to optimize until the system is producing correct results. He's also famous for the "Make it work, make it right, make it fast" quote.

Are you sure he's the source of the quote?

A quick scholar.google.com search found a match in Byte magazine from 1983:

> Furthermore, many C environments contain measurement tools that enable the programmer to identify these critical sections easily. But the strategy is definitely: first make it work, then make it right, and, finally, make it fast.

The Google URL is http://books.google.com/books?ei=dtOXUoCVHoegkAef9YGQBg&id=A... but that's not enough to tell who wrote it. The full text is at http://archive.org/stream/byte-magazine-1983-08/1983_08_BYTE... . Unfortunately, it's OCR'ed, with advertisements and articles intermixed.

I believe it was written by James Joyce.

In any case, it looks like Beck was a ~22 year old undergraduate at the University of Oregon when that was published.

Post reply on HN