You are missing the big picture here of linear search versus indexed search. Optimizations in grep don't magically make it better than O(n).