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

Mysterious run time difference between two different expressions for the same function #49

Open
Glidos opened this issue Jul 30, 2023 · 1 comment

Comments

@Glidos
Copy link

Glidos commented Jul 30, 2023

I have the contents of a file and wish to apply one regex to the first line and another regex to each of the other lines. This runs fast:

case lines contents of
    [] -> []
    h:b -> (:) <$> match hregex h <*> traverse (match bregex) b

This runs slow:

zipWithM match (hregex : repeat bregex) $ lines contents

That's sort of a shame. Just as I'm writing this, I'm realising that the first is probably faster because reductions can be applied to match bregex just once. Still, I'd be interested to hear your thoughts.

@Glidos
Copy link
Author

Glidos commented Jul 30, 2023

This is also fast:

zipWithM ($) (match hregex : repeat (match bregex)) $ lines contents,

so it does look like applying match to just the regex is sort of a trick for precompiling the regex

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

No branches or pull requests

1 participant