This is a submission for high-througput FizzBuzz codegolf. The objective is to generate the highest throughput for FizzBuzz possible. On my personal laptop, this julia script reaches ~10GiB/s, or about triple the throughput of
cat /dev/zero | pv > /dev/null
It supports at most 16 digits, which theoretically takes about a day to reach. At that point, the script terminates with an error.
# For seeing it in action:
julia --threads 4 fizzbuzz.jl
# For benchmarking the throughput:
julia --threads 4 fizzbuzz.jl | pv > /dev/null
# For checking correctness:
diff <( julia --threads 4 fizzbuzz.jl | head -n 10000) <(
seq 10000 | perl -nle'
$_ % 15 or print "FizzBuzz" and next;
$_ % 5 or print "Buzz" and next;
$_ % 3 or print "Fizz" and next;
print'
)
I should credit ais523 for the idea to use the vmsplice
syscall. Theirs is
currently (December 2022) the fastest submission. I also took inspiration from
other solutions to unroll the main loop by 15. The rest of the ideas are my
own, although I'm obviously standing on the shoulders of the giants who created
Julia.