News for hackers. Stuff that matters.
Re:A Little Story About the `yes` Unix Command by mrighele on Thursday October 12, 2017 @04:25AM (#15456480)
As other have pointed out elsewhere what matters here is not much the performance of the language but how much you can avoid calling IO code by making the path as straightforward as possible. You can get comparable performance ( 6.5 GB/s vs 8. GB/s on my machine) with 10 lines of python code, which probably took me the same time to write as the original rust version.
Re:A Little Story About the `yes` Unix Command by e12e on Thursday October 12, 2017 @05:38AM (#15456757)
I'm sure a lot of people would like to see the code for comparison. I know I would.
Re:A Little Story About the `yes` Unix Command by mrighele on Thursday October 12, 2017 @06:22AM (#15456916)
The code is below. I have to admit that after a few more test I realized that the performance greatly depends on the length of the input, in some cases going as low 2 GB/s and some others reaching the performance of the GNU yes installed on my system. This is probably due to the fact that I build the buffer in a quite naive way. With a bit more work maybe that can be fixed.

    #!/usr/bin/python
    import sys

    yes = "yes\n"
    print(sys.argv)
    if len(sys.argv) == 2:
        yes = sys.argv[1] + "\n"

    size = 4096
    buf = bytes(yes * size, 'utf-8')

    while True:
	sys.stdout.buffer.write(buf)