Skip to content

is it faster to call find before calling captures? #803

Answered by BurntSushi
tsoutsman asked this question in Q&A
Discussion options

You must be logged in to vote

Good question. No, you definitely do not want to run find first, as the regex crate will actually do that for you. In cases where the DFA can't be used, then you would wind up making your total time twice as slow as you would just be running the NFA twice.

The example in the grep crate is doing something different. The searcher only reports lines that match. So you have to run the regex again to find the bounds of each individual match, which is strictly more work. Finding the bounds of the line that matches can be done with less work via the shortest_match method. Indeed, that is what the grep crates do internally.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tsoutsman
Comment options

Answer selected by tsoutsman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants