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)
2 Likes

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.

5 Likes

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.

3 Likes

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.

2 Likes

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.

4 Likes

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.

2 Likes

radixsort does use double the memory.

3 Likes

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):

tic
sort(rand(100000000,1));
toc
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.

4 Likes

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Ω
7 Likes

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()
8

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

11 Likes

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

4 Likes

Julia: Code that actually composes

5 Likes

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