Fastest yes in the west There has been a question about yes in the past, but this one is slightly different. You see, despite yes having a rather long size, it is incredibly fast. Running the following command:

timeout 1s yes &gt; out


yields a file that is 1.9 GB. Compared to this program:

int puts();main(){while(1){puts("y");}}


which yields a measly 150 Mb.

The goal is to write a program that outputs y\n (that's y with a newline) repeatedly forever, in as few lines as possible, outputting the biggest size file in as short time as possible. 

The scoring works with the equation: b * y/y'. The value b is the size of your program in bytes. The value of y is the size in bytes of the out file after running the following command: timeout 1s yes &gt; out. The value of y' is the size in bytes of the out file after running the following command: timeout 1s PROG &gt; out where PROG is your program, eg. ./a.out. Your program should match the output of the gnu coreutils program yes ran with no arguments exactly, albeit outputting y at any speed you like. Outputting zero bytes would be a divide by zero in the original equation, resulting in a score of inf for these purposes. 

Lowest score wins.

Edit:

I will run all code on my computer, please show compilation commands and any setup required.

Specs (in case you want to optimize or something):


OS: Arch Linux 5.5.2-arch1-1
CPU: AMD Ryzen 2600X
SSD: Samsung 970 EVO NVMe
RAM: 16GB 3200MHz


Here is a script to calculate the score, since it seems people are having trouble:

b=$(wc -c &lt; $1)
timeout 1s yes &gt; out
y=$(wc -c &lt; out)
timeout 1s $2 &gt; out
y2=$(wc -c &lt; out)
rm out
echo "scale=3;$b*$y/$y2" | bc


Example, given that the script is called score.sh and your program is yes.py:

./score.sh yes.py "python yes.py"
C, 112 bytes, 28 TB/s, score ≈ 0.008

long b[9&lt;&lt;21];main(){for(b[2]=write(*b=1,wmemset(b+8,'\ny\ny',1&lt;&lt;25),1&lt;&lt;27)/2;b[3]=b[2]*=2;ioctl(1,'@ &#148;\r',b));}


(If you’re having trouble copying and pasting this, replace the multicharacter constant '@ &#148;\r' with '@ \x94\r' or 1075876877.)

This writes 128 MiB of y\ns to stdout, and then repeatedly invokes the FICLONERANGE ioctl to double the file’s length by adding new references to the same disk blocks.  Requires Linux x86-64 and a filesystem supporting FICLONERANGE, such as Btrfs or XFS; stdout must be opened in read-write mode (e.g. ./prog 1&lt;&gt; out in bash).

Self-contained testing script

This script loop-mounts a freshly created filesystem from a memory-backed image file and runs the program there.  (I get about 43 TB/s in-memory, but the ratio with yes(1) is similar.)  It works with either Btrfs or XFS, but Btrfs seems to give better scores.

#!/usr/bin/env bash
set -eux
dir="$(mktemp -dp /dev/shm)"
cd "$dir"
trap 'umount fs || true; rm -r "$dir"' EXIT
printf "long b[9&lt;&lt;21];main(){for(b[2]=write(*b=1,wmemset(b+8,'\\\\ny\\\\ny',1&lt;&lt;25),1&lt;&lt;27)/2;b[3]=b[2]*=2;ioctl(1,'@ \\x94\\\\r',b));}" &gt; prog.c
b="$(stat -c %s prog.c)"
gcc -O3 prog.c -o prog
dd of=fs.img bs=1 count=0 seek=8G

# Pick one:
mkfs.btrfs fs.img
#mkfs.xfs -m reflink=1 fs.img

mkdir fs
mount fs.img fs
sync
timeout 1 yes 1&lt;&gt; fs/out || true
y="$(stat -c %s fs/out)"
rm fs/out
sync
timeout 1 ./prog 1&lt;&gt; fs/out || true
y1="$(stat -c %s fs/out)"
echo "score = $b * $y / $y1 = $(bc -l &lt;&lt;&lt; "$b * $y / $y1")"