-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
I compared the performance of three equivalent functions:
pub fn chars_zip(x:&str, y:&str) -> usize {
x.chars()
.zip(y.chars())
.filter(|&(xc, yc)| xc != yc)
.count()
}
pub fn bytes_zip(x:&str, y:&str) -> usize {
x.bytes()
.zip(y.bytes())
.filter(|&(xc, yc)| xc != yc)
.count()
}
pub fn slice_zip(x:&str, y:&str) -> usize {
let x = x.as_bytes();
let y = y.as_bytes();
x.iter()
.zip(y)
.filter(|&(xc, yc)| xc != yc)
.count()
}
This is results (release mode):
chars_zip 0.1450s
bytes_zip 0.2599s
slice_zip 0.0643s
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.