-
Notifications
You must be signed in to change notification settings - Fork 310
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
performance of all_equal #282
Comments
@RSabet That's a very reasonable concern. Note that we must use Release mode compiles to make meaningful performance comparisons. I'm not sure you'll have a different conclusion with that, but you'll have faster timings across the board, and the code will need to be fixed to not optimize out some parts of the benchmark. |
You are right, trying to hide the values in the vector from the optimizer one can use:
again 5_000_000 ones followed by 5_000_000 twos and now in release mode:
|
fn all_equal(&mut self) -> bool
where Self::Item: PartialEq,
{
self.dedup().nth(1).is_none()
} This doesn't necessarily iterate the entire iterator, but in @RSabet's example code, it does evaluate all the 2s. |
342: make all_equal() faster r=jswrenn a=fyrchik Hello! This PR adresses #282 issue. Variant with `dedup` does not short circuit, but one with `all` does. I have also added some benchmarks and test for an empty iterator. ``` test all_equal ... bench: 999,832 ns/iter (+/- 217,245) test all_equal_default ... bench: 4,814,277 ns/iter (+/- 315,335) test all_equal_for ... bench: 2,096,174 ns/iter (+/- 165,596) ``` Let me know, what do you think. Co-authored-by: Evgenii <kraunid@gmail.com>
Solved by #342. |
Here is a comparison of
itertools::all_equal
with two alternatives for a vector consisting of 5_000_000 zeroes followed by 5_000_000 ones on rust playground:itertools::all_equal
: 607 msecsany
: 487 msecsi would love if
all_qual
was as fastplayground
The text was updated successfully, but these errors were encountered: