Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match over benchmarks #10

Open
jamesdbrock opened this issue Dec 14, 2019 · 3 comments
Open

match over benchmarks #10

jamesdbrock opened this issue Dec 14, 2019 · 3 comments

Comments

@jamesdbrock
Copy link

Hi Chris!

I was moved by reading this line your README

lens-regex-pcre only uses pcre-heavy for finding the matches, not substitution/replacement.

to benchmark lens-regex-pcre in my replace-benchmark suite.

I think I'm seeing that, like pcre-heavy, it takes a surprisingly long time when replacing patterns that occurs many times in a string. I haven't investigated, but I suspect it's taking time proportional to the number of matched patterns times the length of the string, which would mean quadratic time complexity in the case where the string is densely filled with patterns. See https://github.com/jamesdbrock/replace-benchmark#results

Or maybe I'm using your library wrong? Is there a better way to write this following program?

main = T.putStr =<< ([regex|x|] . match %~ const "oo") <$> T.getContents

https://github.com/jamesdbrock/replace-benchmark/blob/92290b7f3334c9dfae911fda4ab57e5c1c705998/src/LensRegexText.hs#L10

https://github.com/jamesdbrock/replace-benchmark/blob/92290b7f3334c9dfae911fda4ab57e5c1c705998/src/LensRegexByteString.hs#L9

The sparse benchmark case for lens-regex-pcre is nice and speedy.

Congratulations on publishing Optics by Example, and thanks for writing it!

@ChrisPenner
Copy link
Owner

Oh wow! Yikes, that's pretty unacceptable. Thanks for pointing it out 😄 . Judging from the fact that the pcre-heavy benchmark is slow too, it must be occurring in the match detection part. I have a hard time believing the underlying C lib is that slow, so there must be a glitch somewhere along the way (possibly even in pcre-light). I'll try to remember to take a look under the hood when I have time, this is way worse than it should be.

BTW the idiomatic way would be ([regex|x|] . match .~ "oo") but they expand to the exact same thing 😄

@ChrisPenner
Copy link
Owner

I think I tracked down the issue into pcre-heavy; I created an issue here: valpackett/pcre-heavy#14

Thanks for discovering this!

@ChrisPenner
Copy link
Owner

I can't tag issues in pcre-heavy; but if anyone wants to dig into this issue there for #hacktoberfest that would be great 😄
valpackett/pcre-heavy#14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants