Why is strings faster on a file than it is on stdin?

Posted on

QUESTION :

I wouuld have assumed it would take similar time, maybe 30% difference at most, but it’s wayy off.

Are there any reasons for this?

With Zsh:

Demonstration

And with different shells:

Demo with Bash, Sh, and Fish

ANSWER :

It’s not a problem of strings, it’s a problem of pipes in OSX.

Whatever you do, sending data through a pipe is horribly slow, especially if the read and write sizes are not aligned. Try something along the lines of

cat somefile | cat | cat | cat | cat | cat | strings

to get an idea how much those pipes slow down processing.

Leave a Reply

Your email address will not be published. Required fields are marked *