Me and my colleague have made a bet that Julia can be faster than C++ in several test cases. I will write a set of algorithms in Julia, and he will write the same algorithms in C++, then we will measure the performance.
My question is: what specific* algorithms should I choose to win?
*Our work is related to medical devices and signal processing.
A deep neural net with a diffeq layer on 128-bit floats with confidence intervals embedded. Julia would be faster by default since your opponent wouldn’t be finished coding, so you can grab a beer after finishing in 15 minutes and wait for him to give up.
I think julia`s benefit comes from being a high level language that enormusly helps expressing rather difficult things in C++ very easily at the meantime having comparable performance.
Any heavy numeric code that fulfills these two conditions can easily beat its C++ equivalent:
properly gets SIMD vectorized, check with @code_llvm and look for instructions like 4 x double
avoids bounds checking, by --check-bounds=no compiler option, also try --inline=yes
These are the two major tricks that ifort, e.g., does to beat all competitors. If you have arrays, use StaticArrays or tuples, these are immutable. Finally avoid input/output, strings, and parsing files, Julia still is not as good in these.
Try something that involves evaluating a complex-valued polynomial, e.g. a power-series approximation to a special function. Your friend will be hard-pressed to beat the code generation of the @evalpoly macro for complex arguments, though of course it is theoretically possible to implement this in C++.
I think we’re on the same page here. Someone can definitely match Julia with C++ on any algorithm. The issue is scaling the good algorithms to larger and larger (or more realistic) algorithms. @stevengj’s example is a quick way to do something that, with enough gusto you can get a solution in C++ and match Julia, but the obvious solution is slow and bad. Once your C++ opponent catches up, just scale the amount of the type system and code generation you use and go take a nap.
Julia code complexity scales like O(sqrt(n)) while C++ code complexity scales like O(n^3) (very similar to matrices) where n is the number of lines of code you have to maintain (and there’s an extra effect when build systems get involved). I wouldn’t say C++ can’t do something: just make the point that you don’t want to be the one writing said C++ code.
Ok, I will explain: the purpose is to demonstrate Julia usability and limitations in a concrete context.
I agree, there are other criteria to estimate the usability of Julia for big and complex projects of production-quality. If you know some tutorials or examples of how-to build such projects with Julia, please point me there.
I had some luck in a previous bet with an office mate who was writing some evolutionary algorithm in Matlab. It was a relatively small program, had some nice loops and getindex operations, if-statements introducing branches which can be easily replaced with the branch-free ifelse function. So I accepted the challenge. Half an hour later, bam my program is 8x faster than his Matlab version to the point that he thought I was cheating and using multi-threading I told him I can probably make it 3-8 x faster still if I use multi-threading; the code had some embarrassingly parallel loops. He may not have optimized his Matlab code as much as I optimized my Julia code, but he did take more than half an hour figuring out vectorization tricks, so point made…