12. Doesn't want to show the world how bad the codebase is. Seriously, Mathematica makes naïve python code seem blazingly fast
I've had the displeasure of porting 4k sloc of Mathematica to python and the script runtime went from 40min to 5sec.
12. Doesn't want to show the world how bad the codebase is. Seriously, Mathematica makes naïve python code seem blazingly fast
I've had the displeasure of porting 4k sloc of Mathematica to python and the script runtime went from 40min to 5sec.
[1]Numeric age for D: Mir GLAS is faster than OpenBLAS and Eigen:
http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...
I'll agree that mathematica was really slow (but very expressive) when I played with it last. I think this comes down to it's lispy heritage.
julia is an example of a lang that is fast, but even it can be slow because of GC depending on the workload.
If a Matlab user don't need Simulink or one of it's numerous costly toolboxes, this user should give Julia a try.
While i can't comment on perf, how much of this is due to a rewrite taking advantage of knowledge learned? Would a rewrite in mathematica have been quicker than 40m?
It's best to think of Mathematica as being similar to Python + Numpy. If you want your code to be fast, you want to spend as much time in the kernel (Numpy) as possible. That's why you'll want to take advantage of functional programming constructs, listable functions, etc. if you want to write fast Mathematica code.
He initially wrote an R script, but was extremely slow, so he started rewriting it in C. When I got involved, I found he was calculating this metric with N nested loops, rather than transforming his problem in something that was supported by an existing library or built-in function.
Once he rearranged the problem as a matrix multiplication plus some statistical commands, the R script was faster than the C program and also more readable.
Loops and function calls in R are (or were, last I checked on R 3.x) yet another order of magnitude slower than CPython.
The flipside is that CPython itself has apparently gotten a lot faster in recent versions. In my unscientific homegrown testing, it beats even LuaJIT on string processing tasks.
Still, it offers a very good set of features, and it's cleaner than some popular python libraries.
If that fails Mathematica can also just compile your script for you.