Skip to content

Reading file from disk redirected to stdin is faster than directly from disk #99458

Closed
@Rudxain

Description

@Rudxain

I'm using the byte iterator to get the bytes from a file, and it seems this post is still relevant.

This is my benchmark code:
Direct:

head -c 10000000 /dev/urandom > rand; time ./xorsum rand

Out:

a22b487c4955107f rand

real    0m7.210s
user    0m2.398s
sys     0m4.810s

Redirect:

head -c 10000000 /dev/urandom > rand; time ./xorsum < rand

Out:

5ae99bfc1279743c -

real    0m0.330s
user    0m0.326s
sys     0m0.004s

xorsum is the crate I'm developing. The code I benched is not exactly the same as the one in my repo (Currently. I'll commit my local clone in some minutes after doing some minor changes)
And yes, I ran cargo build -r to optimize it. Memory-mapping and file-caching shouldn't affect bench results, because I always used random data

Update: permalink to the commit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions