Julia seems an order of magnitude slower than Python when printing to the terminal, because of issue with "sleep"

FYI: This Julia program is 2.3s faster (EDIT: the other Julia program is that much faster, but on “real” only, I didn’t notice “user” the first time around) than for python2 (which is slightly faster than python3), despite Julia’s small, but larger startup overhead:

$ time ~/julia-1.9-DEV-76cf1761e6/bin/julia animation3.jl < animation.txt
real	0m16,651s
user	0m1,419s
sys	0m0,899s

old timing I got, I was accidentally timing @GunnarFarneback's original program:
real	0m13,709s
user	0m14,385s
sys	0m1,137s

vs. for Python:
real	0m16,021s
user	0m0,392s
sys	0m0,544s

I can’t take much credit for it, I slightly changed @GunnarFarneback’s program, to use Libc.systemsleep (since busy-waiting is non-ideal, but looking at “user”, it may still be happening?). It improves on the default sleep (which has two issues, and I hope those are fixed). See, the thread this one reminded me of: Is it necessary for sleep to allocate? - #3 by yashi

function main()
    delay = 1.0 / 1200
    data = read(stdin, String)
    for (i, b) in enumerate(data)
        print(b)
        Libc.systemsleep(delay)
    end
end

main()
3 Likes