Specialize Zip::nth for TrustedRandomAccess#48635
Merged
bors merged 3 commits intorust-lang:masterfrom Mar 3, 2018
Merged
Conversation
Makes the bench asked about on URLO 58x faster :)
Contributor
|
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
Member
|
Could you add a test to ensure side effects are executed? fn main() {
let mut a = Vec::new();
let mut b = Vec::new();
let value = (1..7)
.map(|n| {
a.push(n);
n * 10
})
.zip((2..9).map(|n| {
b.push(n * 100);
n * 1000
}))
.skip(1)
.nth(3);
assert_eq!(value, Some((50, 6000)));
assert_eq!(a, vec![1, 2, 3, 4, 5]);
assert_eq!(b, vec![200, 300, 400, 500, 600]);
} |
Member
Author
|
@kennytm Good call. It looks like |
kennytm
reviewed
Mar 1, 2018
src/libcore/iter/mod.rs
Outdated
|
|
||
| #[inline] | ||
| default fn nth(&mut self, n: usize) -> Option<Self::Item> | ||
| { |
Member
There was a problem hiding this comment.
Minor nit: why this { is on a new line 😄
Member
Author
There was a problem hiding this comment.
Now that is an excellent question 😅
src/libcore/iter/mod.rs
Outdated
|
|
||
| #[inline] | ||
| fn nth(&mut self, n: usize) -> Option<Self::Item> | ||
| { |
Member
|
Travis passed, so @bors r+ |
Collaborator
|
📌 Commit 5105fc1 has been approved by |
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Mar 3, 2018
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Mar 3, 2018
Specialize Zip::nth for TrustedRandomAccess Fixes the performance difference observed in https://users.rust-lang.org/t/performance-difference-between-iterator-zip-and-skip-order/15743 Before: ``` test iter::bench_skip_then_zip ... bench: 154 ns/iter (+/- 4) test iter::bench_zip_then_skip ... bench: 4,725 ns/iter (+/- 225) ``` After: ``` test iter::bench_skip_then_zip ... bench: 154 ns/iter (+/- 2) test iter::bench_zip_then_skip ... bench: 81 ns/iter (+/- 19) ```
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Mar 3, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the performance difference observed in https://users.rust-lang.org/t/performance-difference-between-iterator-zip-and-skip-order/15743
Before:
After: