Skip to content

Terrible perfomance of the iterator str::bytes().zip(str::bytes()) #44424

Closed
@IBUzPE9

Description

@IBUzPE9

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

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions