10 ms·
The /r/programming discussion of this is interesting [1]. Someone does a Go version and gets the same speed as GNU yes. Someone else tries several languages. T
by tzs 9y ago
The /r/programming discussion of this is interesting [1].
Someone does a Go version and gets the same speed as GNU yes. Someone else tries several languages. This person got the same speed in luajit, and faster in m4 and php. Ruby and perl about 10% slower, python2 about 10% slower still, and python3 about half that. The code is given for all of these, and subsequent comments improved python3 about 50% from his results, but still not up to python2.
[1] https://www.reddit.com/r/programming/comments/6gxf02/how_is_gnus_yes_so_fast_xpost_runix/ https://www.reddit.com/r/programming/comments/6gxf02/how_is_...
- dom0 9y agom4 is orders of magnitude slower (notice the different unit). If you write the Python script using bytes (not Unicode), then Python 3 is faster than Python 2, at least for me. Python 3 is 20 % slower than GNU yes and Python 2 35 % slower than GNU yes. e: I think in your last sentence you are comparing results from different computers.
- psittacus 9y agoThis[1] comment seems directly opposite from what you wrote, with Python 3.4 (8.76GiB/s) even outrunning Python 2.7 (8.55 GiB/s). (haven't run the tests myself though) edit: haven't noticed the comment by dom0. [1] https://www.reddit.com/r/programming/comments/6gxf02/comment/diu4l0x https://www.reddit.com/r/programming/comments/6gxf02/comment...
- fredmorcos 9y agoThank you for incorrectly pointing out what can be trivially found in the linked post.
- acomjean 9y agoI had to smile, as this thread is a microcosm of programming language stereotypes: with the python programmers tweaking code to get that extra 10% (nobody mentioned pypy..), someone trying to get javascript to work in a long running program, of course a rust implementation that isn't working well just yet (but we're all rooting for it.. set that compiler flag and rerun).. One comment about perl (turns into a one liner..). Nobody bothering to redo the Lua, Ruby and PHP. And for fun somebody throws down some fortran. what is going on with the m4 code?
- jrimbault 9y agoOne night for fun, I wrote a fizzbuzz (without actual printing) in almost all of the languages mentionned here (except fortran), and benchmarked it with 10000 executions each.
- sevensor 9y agoAnd? Don't leave us hanging! Who wins at FizzBuzz? Also, surely 10k is just getting started?
- jrimbault 9y ago10k was just sufficient to get actual differences. Of course I went crazy and did something like 10M, but waiting 10 minutes to get the same relative differences didn't bring anything. Remember this is without any printing: C is fast, if I remember correctly it was something like 0.015 or 0.03s while at the other end of the spectrum I had to wait 0.1s for JavaScript. C results varied from simple to double because of the OS I guess because it was so quick. It isn't a really significant benchmark though, for any language. It was one of those nights. Ah, and I remember a large difference between go run and go install.
- sevensor 9y ago> It isn't a really significant benchmark though, for any language Sure, but it's reassuring to know that the universe is still sane, C is still faster than Javascript. Thanks for expanding on your comment!
- jrimbault 9y agoFound the old sources, reran the benchmark for 100 times each. c 0.062s f90 0.080s go 0.108s awk 0.116s lua 0.117s rs 0.140s sh 0.434s php 0.886s scm 1.323s py 2.965s rb 3.738s js 5.411s My memory was bad, I also added fortran for the occasion.
- hultner 9y agoActually the second python version is about on par, however it's running on a slower system. He got 6.78GiB/s from GNU yes and 6.76GiB/s with python3. Some one later compares it with python2 which in fact is slower with this codebase. > $ python2.7 yes.py | pv > /dev/null > ... [7.22GiB/s] ... > $ python3.4 yes.py | pv >/dev/null > ... [8.76GiB/s] ..
- zanny 9y agoI was under the impression Python was magnitudes slower than compiled native languages, even when you aren't abusing Pythonic features that are computationally expensive like list comprehensions. And this isn't even in Pypy where this loop would be JIT'd and then run natively anyway, unless cpython does some kind of JIT? Is is just that the buffer is so large that the kernel handler is taking so much of a % of the runtime that the inefficiencies of the language stop mattering?
- Derbasti 9y agoAssuming that ‘yes‘ is primarily limited by memory performance and kernel calls, the language runtime should have little influence.
- rurban 9y agoActually I got perl beating all others by far. Easy, because you can control the buffer size. darwin with BSD + GNU yes, vs some scripting langs: $ /usr/bin/yes | pv > /dev/null ^C00MiB 0:00:04 [23.9MiB/s] [ <=> $ /opt/local/libexec/gnubin/yes | pv > /dev/null ^C77GiB 0:00:05 [ 644MiB/s] [ <=> $ bash -c 'while true; do echo "y"; done' | pv > /dev/null ^C38KiB 0:00:03 [ 233KiB/s] [ $ node -e 'while (true) { console.log("y"); }' | pv > /dev/null ^C57MiB 0:00:03 [ 582KiB/s] [ $ perl6 -e 'loop { print "y\n" x (1024*8) }' | pv > /dev/null ^C295MiB 0:00:02 [ 139MiB/s] [ <=> $ ruby -e 'while true do puts("y"*1024*8) end' | pv > /dev/null ^C14GiB 0:00:09 [ 827MiB/s] [ $ python2.7 -c 'while True: print "y\n" * (1024*8),' | pv > /dev/null ^C.3GiB 0:00:10 [1.73GiB/s] [ <=> $ python3.6 -c 'while True: print("y\n" * (1024*8)),' | pv > /dev/null ^C73GiB 0:00:05 [1.79GiB/s] [ <=> $ perl -C0 -E 'print "y\n" x (1024*8) while 1' | pv > /dev/null ^C.6GiB 0:00:08 [1.84GiB/s] [ <=>