# Julia slower than Python to sort and reverse a list of integers

**URL:** https://discourse.julialang.org/t/julia-slower-than-python-to-sort-and-reverse-a-list-of-integers/97453
**Category:** Performance
**Created:** [April 13, 2023, 10:45pm UTC](https://discourse.julialang.org/t/julia-slower-than-python-to-sort-and-reverse-a-list-of-integers/97453 "2023-04-13T22:45:57Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [April 13, 2023, 11:38pm UTC](https://discourse.julialang.org/t/julia-slower-than-python-to-sort-and-reverse-a-list-of-integers/97453/9 "2023-04-13T23:38:36Z")

</div>

I think it’s that Python buffers stdout by default and Julia doesn’t.

> <https://github.com/JuliaLang/julia/issues/43176>
>
> \<!--
> If you have a question please search or post to our Discourse site: https:…//discourse.julialang.org.
> We use the GitHub issue tracker for bug reports and feature requests only.
> 
> If you're submitting a bug report, be sure to include as much relevant information as
> possible, including a minimal reproducible example and the output of \`versioninfo()\`.
> If you're experiencing a problem with a particular package, open an issue on that
> package's repository instead.
> 
> Thanks for contributing to the Julia project!
> \--\>
> In brief: Julia println output speed seems oddly slow, or costly, in an interactive terminal compare to several other languages. The slow behavior is only occurring in an interactive terminal (tried several such as gnome-terminal, xterm, qterminal, sakura, emacs-vterm). No slowness are visible when the standard output is redirected.
> 
> 1) In details (Linux Debian sid, julia 1.5.3, similar behavior on several x86\_64 (Intel, AMD))
> I wrote recursive Fibonacci computation with printf inside (Julia code below), in several languages for, e.g., demonstrating the synchronization in a terminal for my OS lecture. Julia computation performance is on par with C, C++, Rust, Fortran, Go, Crystal, without the println, but, with the println, Julia is much much slower (2.5 - 6.5 times slower) than even python3, perl5, ruby or node-js. Only Raku is slower but because the Raku 2021.09 computation are still very slow.
> 
> If the output is redirected to /dev/null, Julia is again on par with the fastest languages.
> The most comparable language I tried, "crystal" (ruby compilation with LLVM), does not have the same behavior.
> 
> 2) Remarks:
> According to /usr/bin/time ('time" package in Debian) Julia seems to spend much more time in the kernel: twice the time compare to perl or python.
> 
> perf trace julia... records roughly 4M syscalls for fibo(30) compare to roughly 1M in C, perl or python, and 2M for crystal
> 
> perf record/report indicates VDSO gettimeofday at the top (3%)
> 
> 3) My Fibonacci code:
> \`\`\`julia
> import Printf: @printf
> 
> function fibo\_println(n)
> if n \< 2
> return n
> end
> val = fibo\_println(n-1) + fibo\_println(n-2)
> println(val)
> return val
> end
> 
> n = 20
> if length(ARGS) \> 0
> n = parse(Int64, ARGS\[1\])
> end
> 
> v, t = @timed fibo\_println(n)
> @printf(stderr, "julia fibo(%d)= %lld en %lld s\\n", n, v, t)
> \`\`\`

> <https://github.com/JuliaLang/julia/issues/36639>
>
> https://discourse.julialang.org/t/why-is-printing-to-a-terminal-slow/42987
> 
> Re…quires a terminal that can render output fast (seems like iTerm2 doesn't) to demonstrate.

from

> [@Why is printing to a terminal slow?](https://discourse.julialang.org/t/why-is-printing-to-a-terminal-slow/42987/22):
>
> A different use of printing to stdout/stderr is to pipe output through less (or similar pager) to be able to inspect the output interactively without having to do a full (long) run. E.g. grep for certain strings in the output to check a condition, then letting the program continue until the next matching line, etc. I find this very useful during development. In this case you will also hit upon the slower output of Julia compared to Python. A simple (rough, due to the user keyboard interaction)…

---

_[View the full topic](https://discourse.julialang.org/t/julia-slower-than-python-to-sort-and-reverse-a-list-of-integers/97453)._
