-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add an iterator version of wrap
#79
Conversation
@mgeisler Sorry for the wait, I was messing with docs at the time. |
Some questions:
|
So |
src/lib.rs
Outdated
|
||
// String to wrap. | ||
source: &'a str, | ||
// Fused CharIndices iterator over self.source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Remove "Fused"
Hey @hcpl! Thanks very much for this -- the first outside contribution :-) I think it looks very nice and would like to merge it. However, I just tried to run the benchmarks and compared them with
The comparison was simply:
I haven't looked into why this can be yet -- maybe you have an idea? |
@mgeisler I believe the slowdown is caused by cloning, because both In case if cloning with such a slowdown is not desirable, we can internally utilize a borrowing variant of And there can be consuming |
Now iterator-based methods of Wrapper are split into 3 variants:
Latest benchmark results:
|
Awesome that you found a good solution so fast! I just ran the benchmarks on my machine and somehow the hyphenation benchmarks are faster now:
That's pretty cool and the other slowdowns are fine too :-) |
Thanks for working on this! I was wondering if all three methods are really needed:
Would it not be enough to just offer the However, it seems like a lot of infrastructure for something that should be simple :-) As I said somewhere, I'm still new to Rust (coming from Python), so I'm still trying to get used to the style of the language. |
For evidence I just ran benchmarks again:
So for something countable in nano-/microseconds, I wouldn't pay much attention to speedups/slowdowns with less than 25% of difference. They just fall within the margin of error, IMO.
At least, we need the
That's what I particularly like about Rust, because "a lot of infrastructure" in a way that Rust API tends to have is an example of "Explicit is better than implicit." done well. Users are presented with different options, so that they are able to pull maximum performance out of every possible use case. But that doesn't necessarily mean limiting oneselves only to "fastest" solutions -- users are free to do however they want if that helps to keep their code simple, even if doing so needs sacrificing a bit (or a lot) of performance. Last but not least, Rust (and accompanying
You're welcome! :D |
Thanks for the explanations, much appreciated! I think I'll try renaming
I think that will be rare and that a simple borrowing iterator is enough in most cases. I'll put up a PR and add you as a reviewer. |
#[derive(Clone)]
for word splitter types defined in this crate (hyphenation::Corpus
already has aClone
impl);Clone
requirement (which should be considered a breaking change but I think there are no custom word splitters to worry about);