How fast are Linux pipes anyway?
For some reason, this raised my curiosity how fast different languages write individual characters to a pipe:<p>PHP comes in at about 900KiB/s:<p><pre><code>    php -r 'while (1) echo 1;' | pv > /dev/null
</code></pre>
Python is about 50% faster at about 1.5MiB/s:<p><pre><code>    python3 -c 'while (1): print (1, end="")' | pv > /dev/null
</code></pre>
Javascript is slowest at around 200KiB/s:<p><pre><code>    node -e 'while (1) process.stdout.write("1");' | pv > /dev/null
</code></pre>
What's also interesting is that node crashes after about a minute:<p><pre><code>    FATAL ERROR: Ineffective mark-compacts
    near heap limit Allocation failed -
    JavaScript heap out of memory
</code></pre>
All results from within a Debian 10 docker container with the default repo versions of PHP, Python and Node.<p>Update:<p>Checking with strace shows that Python caches the output:<p><pre><code>    strace python3 -c 'while (1): print (1, end="")' | pv > /dev/null
</code></pre>
Outputs a series of:<p><pre><code>    write(1, "11111111111111111111111111111111"..., 8193) = 8193
</code></pre>
PHP and JS do not.<p>So the Python equivalent would be:<p><pre><code>    python3 -c 'while (1): print (1, end="", flush=True)' | pv > /dev/null
</code></pre>
Which makes it compareable to the speed of JS.<p>Interesting, that PHP is over 4x faster than the Python and JS.