I think you shouldn't need to escape to regex for performance. I don't understand why would regex crate be so much faster in Rust? Some crazy optimizations the nom doesn't make?
Not an parser guru, but when I used megaparsec in Haskell course, I never thought I should switch to regex for speed.
Yes, there are crazy optimizations in the regex crate. :-)
But it almost certainly depends on what you're doing. If you're using Nom, you're probably performing a parsing task. A regex might be faster there, but maybe not by too much, depending. If you're doing a searching task though, perhaps where there are few matches relative to the size of the haystack, then it's quite plausible that the regex will go a lot more than 3x as fast as Nom.
In any case, I'm not sure if Haskell is comparable. I'm not sure that any Haskell native regex engine is really known for its speed, although I haven't done any sort of comprehensive benchmarking.
There are other considerations. A parser written with Nom might be easier to read and/or manipulate than a parser written with regex. But even there, it depends.
Comments
I think you shouldn't need to escape to regex for performance. I don't understand why would regex crate be so much faster in Rust? Some crazy optimizations the nom doesn't make?
Not an parser guru, but when I used megaparsec in Haskell course, I never thought I should switch to regex for speed.
Yes, there are crazy optimizations in the regex crate. :-)
But it almost certainly depends on what you're doing. If you're using Nom, you're probably performing a parsing task. A regex might be faster there, but maybe not by too much, depending. If you're doing a searching task though, perhaps where there are few matches relative to the size of the haystack, then it's quite plausible that the regex will go a lot more than 3x as fast as Nom.
In any case, I'm not sure if Haskell is comparable. I'm not sure that any Haskell native regex engine is really known for its speed, although I haven't done any sort of comprehensive benchmarking.
There are other considerations. A parser written with Nom might be easier to read and/or manipulate than a parser written with regex. But even there, it depends.
Combinator alternatives, especially nested ones, will "naively" iteratate over cases until match is found.
In regexp those (nested) alternatives may be expressed much more efficiently as state machine or whatever.