In as few lines as possible describe why you love julia

@fjfranco, even if stretching it by one order of magnitude and running the Julia REPL on a cell phone it wasn’t enough time to get an espresso shot ready…

julia> @time sort!(rand(Float64, 100_000_000))
 12.751227 seconds (25 allocations: 762.959 MiB, 0.23% gc time)

This is the first example I propose in Julia seminars to amaze my students!

Enjoy your expresso!

1 Like

The beauty of Julia language, specially in OhMyREPL colors:

NB: snapshot of Android cellphone REPL.
Post edited because of censorship.


Have you tried it in other languages? Could you explain what’s your point in this example?

It seems to be fast in any language with an efficient sort() and rand() functions.
For example, MATLAB (R2021a):

>> tic; sort(rand(1e7, 1)); toc;
Elapsed time is 0.223402 seconds.

Python (3.9.4 + MKL):

%timeit np.sort(np.random.rand(10_000_000))
811 ms ± 3.89 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

For reference, this is Julia (1.6.1) on my machine:

julia> @time sort!(rand(Float64, 10_000_000));
  0.733050 seconds (2 allocations: 76.294 MiB, 9.77% gc time)

It doesn’t seem Julia is exceptionally fast in this example (Even though it has the advantage of working in place). I find Julia having in place sort() to be a nice advantage. But that’s hardly the bottleneck here.

Is sort() written in Julia? Was that your point? Having the sort() function written in a dynamic language and be fast (Same scale) as c? If so, it is indeed impressive.


Sometimes I’m just amazed at how fast computers can calculate things… :slight_smile:

What is this? Do you have a link? Does it work with android? Do I need to be root?

No need for root in Android, just follow this great post.

1 Like

Even faster

using SortingAlgorithms
@time sort!(rand(Float64, 10000000), alg=RadixSort)

Try the above. It’s faster.


Faster, I suspect

using SortingAlgorithms
@time sort!(rand(Float64, 100_000_000), alg=RadixSort)
1 Like

Because Julia people don’t quit(); the exit() gracefully.


Yes, this is ~20% faster and nice to know about that package!
However, it seems more unstable on my cellphone: sometimes the process aborts saying “Killed” or it can even abort the Julia REPL.

That’s what happens when you run out of memory on Linux.


radixsort does use double the memory.


Try this and MATLAB will not be faster any more. Future implementations of other algorithms into ThreadsX can get even faster. The Multithreading hero, aka @tkf, may give us more insights.

using ThreadsX
julia> @time ThreadsX.sort!(rand(Float64, 100_000_000));
  3.376360 seconds (4.29 M allocations: 1.973 GiB)

MATLAB (R2020a) for reference (multithreaded by default):

Elapsed time is 3.731379 seconds.

I wish, in some way, all allocating functions would support given a pre allocated buffers on the function call.
To the least the in place flavors.
It means the user will be able to create a non allocating paradigm (Pre allocating all at the beginning of the program and from there just recycling the buffers).
It will probably also help the GC, right?

Maybe something to think about for Julia 2.0.
It can become very important in production.


Tagging @tro3 and @stillyslalom:

julia> using Unitful, Unitful.DefaultSymbols

julia> 800mV/53.55μA
14.939309056956116 mV μA^-1

julia> uconvert(kΩ, ans)
14.939309056956116 kΩ

Even better with some syntactical sugar

julia> using Unitful, Unitful.DefaultSymbols

julia> 800mV/53.55μA |> kΩ
14.939309056956116 kΩ

Yes, radix sort is great. So let’s parallelize it :slight_smile:

julia> using SortingAlgorithms, ThreadsX, ParallelRadixSort

julia> x = rand(Float64, 100_000_000);

julia> @time sort(x, alg = RadixSort);
  3.495047 seconds (18 allocations: 1.490 GiB)

julia> @time sort(x, alg = ThreadsX.QuickSort);
  2.001733 seconds (4.22 M allocations: 1.895 GiB, 5.03% gc time)

julia> @time sort(x, alg = ParallelMSDRadixSort);
  1.174623 seconds (134.32 k allocations: 1.496 GiB, 9.39% gc time)

julia> Threads.nthreads()

(All @times are not the first run since ParallelMSDRadixSort seems to have a large compilation overhead ATM.)


Julia, you are my only hope to escape from the heavily templated clutches of evil C++ Emperor with an awful syntax!


Julia: Code that actually composes


nice. I see the code is using MSD radix sort which only works if the data is “balanced” which happens to be the case for random data like this.

I would be interested in skewed data sorting with ParallelRadixsort!

1 Like