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

**URL:** <https://discourse.julialang.org/t/julia-seems-an-order-of-magnitude-slower-than-python-when-printing-to-the-terminal-because-of-issue-with-sleep/78151>\
**Category:** General Usage\
**Tags:** performance\
**Created:** [March 20, 2022, 4:17am UTC](https://discourse.julialang.org/t/julia-seems-an-order-of-magnitude-slower-than-python-when-printing-to-the-terminal-because-of-issue-with-sleep/78151 "2022-03-20T04:17:43Z")\
**Posts on this page:** 1\
**Showing post:** 29

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [March 21, 2022, 12:32pm UTC](https://discourse.julialang.org/t/julia-seems-an-order-of-magnitude-slower-than-python-when-printing-to-the-terminal-because-of-issue-with-sleep/78151/29 "2022-03-21T12:32:20Z")

</div>

> [@kdheepak](#):
>
> Python finishing in 0.04 seconds but Julia takes 0.70 seconds. This makes certain kinds of animations / widgets in the terminal untenable in Julia

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:

```julia
$ 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](https://discourse.julialang.org/t/is-it-necessary-for-sleep-to-allocate/77795/3)

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

main()

```

---

_[View the full topic](https://discourse.julialang.org/t/julia-seems-an-order-of-magnitude-slower-than-python-when-printing-to-the-terminal-because-of-issue-with-sleep/78151)._
