Live data from Hacker News

How efficient can cat(1) be?

ariadne.space

1–10 of 51 posts

Re: How efficient can cat(1) be?

#3
post #2

This was a good read! The missing hyperlinks: - https://man7.org/linux/man-pages/man2/sendfile.2.html - https://man7.org/linux/man-pages/man2/splice.2.html (Funny how used I've gotten to "hypertext", I was quite irritated I couldn't click those function names.)

Pinfo makes regular man pages navigable.

Re: How efficient can cat(1) be?

#5

copy_file_range is much preferable to any of these because filesystems can "hook into" it and just share the underlying data, not copying at all.

In general, yes, but as the article notes, itt's not applicable to cat, as cat always outputs to stdout and not to a file.

Re: How efficient can cat(1) be?

#6

copy_file_range is much preferable to any of these because filesystems can "hook into" it and just share the underlying data, not copying at all.

In general, yes, but as the article notes, itt's not applicable to cat, as cat always outputs to stdout and not to a file.

You can handle the cat foo bar baz > file case this way though, because stdout is a file then.

Re: How efficient can cat(1) be?

#7
post #2

This was a good read! The missing hyperlinks: - https://man7.org/linux/man-pages/man2/sendfile.2.html - https://man7.org/linux/man-pages/man2/splice.2.html (Funny how used I've gotten to "hypertext", I was quite irritated I couldn't click those function names.)

Also: https://man7.org/linux/man-pages/man2/copy_file_range.2.html

Re: How efficient can cat(1) be?

#8

Earlier quoted context omitted.

In general, yes, but as the article notes, itt's not applicable to cat, as cat always outputs to stdout and not to a file.

You can handle the cat foo bar baz > file case this way though, because stdout is a file then.

that is why the article mentions it as an honorable mention :P

Re: How efficient can cat(1) be?

#9
A bit of a tangent, there are few instances of "do-while" that I've ever ever written and not removed soon after. In practice, I've found that the looping situations that don't easily match the "for (int i = 0; i
    do
    {
        splice(from stdin...);

        if (A)
            handle_a();
            goto out;

        splice(to stdout...);

        if (B)
            handle_b();
            goto out;

    } while (nwritten > 0);

   // do we need some kind of handle_c()??

    out:
        ...
Why make a special case for the "nwritten > 0" condition here? And what's wrong with "break" vs "goto"?

    for (;;)
    {
        thing_a();

        if (A)
            handle_a();
            break;

        thing_b();

        if (B)
            handle_b();
            break;

        if (C)
            handle_c();
            break;
    }
is cleaner in my eyes.

Re: How efficient can cat(1) be?

#10
Slightly out of topic:

> There have been a few initiatives in recent years to implement new a new userspace base system for Linux distributions as an alternative to the GNU coreutils and BusyBox.

Have there been? And why?

Post reply on HN