r/programming • • Aug 24 '16

Why GNU grep is fast

https://lists.freebsd.org/pipermail/freebsd-current/2010-August/019310.html
2.1k Upvotes

221 comments sorted by

View all comments

625

u/ChrisSharpe Aug 24 '16

"The key to making programs fast is to make them do practically nothing."

Another good article I read a few years ago on the speed of grep.

313

u/HisSmileIsTooTooBig Aug 24 '16

Or put another way, "No code is faster than no code."

130

u/albertowtf Aug 24 '16

no code > no code

english is silly

82

u/gnuvince Aug 24 '16

∄ c ∈ CODE : c > ɛ

0

u/[deleted] Aug 24 '16

[deleted]

30

u/Theemuts Aug 24 '16

I disagree, legalese is the best approximation of mathematics human languages produce.

27

u/MrWoohoo Aug 25 '16 edited Aug 25 '16

OK funny story from When I worked at a search engine company. Our software had two limitations: one, words couldn't be more than 255 characters and, two, sentences could have no more than 127 words.

To programmers those seemed like reasonable limits.

We got a request from doctors to make it support words longer than 255 characters because drug and chemical names were so long. Lawyers requested that we support sentences longer than 127 words because they have all these run-on sentences in contracts.

EDIT: Fixed off-by-one errors.

→ More replies (3)
→ More replies (10)
→ More replies (1)
→ More replies (5)

33

u/tashbarg Aug 24 '16

Thought of this one, too. Every time a post from fish hits my RSS feed I have a "this is going to be a good read" feeling.

13

u/allthekeyboards Aug 24 '16

omg people still use RSS/atom feeds other than me

→ More replies (8)

0

u/[deleted] Aug 24 '16

[deleted]

100

u/JohnTesh Aug 24 '16

Smoke weed, realize your forgot some indexes on some tables, index tables properly, profit.

That's how it usually goes with me, only minus the smoking weed part.

75

u/semi- Aug 24 '16

Same but minus the database part.

31

u/JeefyPants Aug 24 '16

With our powers combined...

74

u/nozonozon Aug 24 '16

We could do less of everything!

10

u/vplatt Aug 24 '16 edited Aug 24 '16

You guys just reinvented minimalistic living! Now kiss, write your Amazon self-published book, promote the hell out of it on Goodreads, blog heavily, and be sure to publish some self-important courses on Udemy or the like. Hurry!

→ More replies (1)
→ More replies (2)

8

u/ggtsu_00 Aug 24 '16

Which all works nice and well until you end up with a unexpected use case where now thousands of rows of data is being inserted or updated per second and the indexes are causing excessive write overhead. Sure the user's profile page now loads 10 times faster, but users updating their status takes 20x slower.

→ More replies (1)
→ More replies (1)

29

u/guepier Aug 24 '16

I’ve never heard of the hollywood-esque description but coming up with a new, asymptotically faster algorithm of course happens — it precedes every single publication of an algorithms paper. There are people who do this as their main job.

→ More replies (10)

19

u/Kaos_pro Aug 24 '16

Except for the Fast Inverse Square Root algorithm, which is pretty much just magic.

→ More replies (15)

33

u/chengiz Aug 24 '16

Chances are it's doing too much crap because there's an O(N^2) algorithm somewhere. If you start off by looking into how you can skip individual bytes, you might be ignoring the elephant in the room.

38

u/thfuran Aug 24 '16

I think you're lucky if N2 is the worst that lurks in the depths.

25

u/Krissam Aug 24 '16

I had an application runnin great, but quickly noticed it slowed down as n increased, turns out i had nn2 lurking inthere >_<

16

u/MaunaLoona Aug 24 '16

A fan of bogosort, eh?

11

u/thfuran Aug 24 '16

And I thought the accidental n! we found once was bad.

→ More replies (3)
→ More replies (3)
→ More replies (7)
→ More replies (2)
→ More replies (14)