In as few lines as possible describe why you love julia

I was a convert when I rewrote a code that I had originally developed in Matlab. The code I’d written was intended to improve a commercial software I use at work that was painfully slow and completely manual. Thanks to writing the algorithm myself in Matlab I was able to improve the performance significantly and was automated. I rewrote the code in Julia and due to a number of things I was able to cut my LOC by ~20x, reduce required memory by orders of magnitude, and get a sizeable speedup.

I posed the basics of the problem to the Julia discourse and received great feedback from the community.

Here’s a graphic I made for management shortly after my Julia rewrite. All told ~20,000 faster than the commercial code for a big-small (10k cells) problem and it made large problems (1M cells) tractable.

image

43 Likes

Only discovered this today:

julia> mV = 1e-3
0.001

julia> uA = 1e-6
1.0e-6

julia> 800mV/53.55uA
14939.30905695612

(I assume that the “symbol-less” multiply takes a precedence I didn’t expect.) Too bad I don’t get the kOhm for free… :slight_smile:

6 Likes

You can’t get it for free, but you can still get it pretty cheap:

julia> using Unitful, Unitful.DefaultSymbols

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

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

Jolly Useful Language I Approve

9 Likes

Julia Unlocks Loads of Intelligent Algorithms

Julia Using Lisp Is Awesome

julia> using Looping, IncompleteLU, ApproxFun

sorry, once I get my teeth into something …

6 Likes

Someone once proposed “Julia Users Love Impressive Arithmetic” as a recursive retronym for Julia, and I’ve always rather liked that :yum:

28 Likes

I like this thread better.

4 Likes

@klaff but remember Julia (the) Ultimate Language Isn’t (an) Acronym

6 Likes

From their README:

If you want to use your custom convex objects, you can do so by extending the support function as:

import ConvexBodyProximityQueries.support
function ConvexBodyProximityQueries.support(obj::MyFancyShape, dir::SVector{N}) where {N}
  # do something
  return supporting_point::SVector{N}
end

Our something:

using LazySets

function ConvexBodyProximityQueries.support(obj::LazySet{N}, dir::SVector{D, N}) where {D, N}
    return LazySets.support_vector(dir, obj) |> SVector{D, N}
end

Congrats! :tada: You have unlocked Gilbert–Johnson–Keerthi distance algorithm for any lazy set :stuck_out_tongue:

# random test
X = rand(HPolygon)
Y = rand(VPolygon)
M = rand(2, 100)
Z = rand(Zonotope, dim=100) ⊕ ones(100)*20.
dir = @SVector(rand(2))
minimum_distance(X ⊕ Y, M*Z, dir)
520.1355965708728
5 Likes

Could you try to explain in a “basic way”, how it is possible for Julia code to be faster than C?

Maybe the question, I am asking, it self is wrong, but I always thought that Julia, at the end of things was running on some version of C?

Kind regards

1 Like

Few years back, I opted for Julia ( version 0.3.something at the time) for:

  1. Super ease of coding for parallel processing.
  2. Syntactic sweetness (above Python, IMHO).
  3. Lots of built-in features/functions for math intensive code.
  4. All three above with performance so close to C.

And it has been a delight to fathom Metaprogramming and Multiple Dispatch.

3 Likes

Julia does whole program optimization by default, whereas C has boundaries at shared libraries. When you write generic code in C, you have to use void pointers, and it does not get specialized for different types; in Julia it does automatically with no special tricks required by the programmer. Julia is also better at code generation, so, for example C code typically uses a static array of coefficients to do Horner evaluation of polynomials, whereas in Julia the coefficients are inlined into the code that’s generated.

16 Likes

Long time R & MATLAB user. Starting learning Julia about a month ago.

Rewrote c# financial simulation engine in Julia. c# is thousands of line long and requires expensive matrix/math/stats libraries. Julia is 100’s of lines of code. The Julia Code looks/writes similar to the c# because we don’t need to vectorize.

Julia single threaded speed is about the same as the c# multi-threaded! Using the experimental threading scales almost 1 to 1. So now Julia Code is 4-5x times faster.

Julia Code is faster, more maintainable, and a whole lot easier to experiment with thnt the c#. Now I am not reliant on the c# devs for research.

34 Likes

Open REPL, type this, press enter and go to make coffee.

@time sort!(rand(Float64, 10000000))

Probably, you hadn’t pulled back your chair before the instruction is executed.

3 Likes

@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?