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.
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.
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
# 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
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.
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.
@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…
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.