Closed Xitian9 closed 3 years ago
Those are nice improvements. However, I would like that reflected in the commit message. For example:
Improve performance of Cell and StringBuilder instances
I've been following a specific style in my later commits. The title starts with a verb in infinitive form and does not end with a dot. If you want to specify details you are encouraged to do so (although preferably for complex commits) after a blank line.
I'm not sure whether the improvement for dropRight
is actually faster. And after all, most strings are relatively short, i.e. one could consider this premature optimization, not that performance matters anyway with String
or we are printing tables a lot. ;)
I'm happy to drop this PR if you want. They were just things I noticed as potential (and potentially small) improvements. I think you're likely correct that there's little to know real performance difference in most cases.
I presume you mean imperative form rather than infinitive? (Infinitive would be “To improve performance of Cell and StringBuilder instances”).
The advantage of this dropRight
here is that it avoids reversing the list twice, and is lazier. In fact, this version will actually work on infinite lists. How much of a benefit this is is questionable, but I believe it's strictly better. (See discussion here https://www.reddit.com/r/haskell/comments/f072u/sample_solution_to_an_early_project_euler_problem/c1ceny6?utm_source=share&utm_medium=web2x&context=3)
I'm happy to drop this PR if you want. They were just things I noticed as potential (and potentially small) improvements. I think you're likely correct that there's little to know real performance difference in most cases.
No, I like it.
I presume you mean imperative form rather than infinitive? (Infinitive would be “To improve performance of Cell and StringBuilder instances”).
Yes, my bad.
In fact, this version will actually work on infinite lists. How much of a benefit this is is questionable, but I believe it's strictly better.
I guess then length
would be our next problem. But I found the argument with constant space convincing.
Avoid reversing strings twice.