6 ms·
1 - 11: $$ 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 displea
by VHRanger 5y ago
1 - 11: $$
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.
- wyldfire 5y agoAt first I thought, "how could anything be slower than python?" And then I figured that you probably would've ported it to leverage things like numpy which makes a lot of operations into native code and takes advantage of highly optimized blas libs, etc.
- antoinealb 5y agoEven native python is not as slow as people expect. And scientific languages are terribly slow, see for example loops in Matlab, which are terribly slow.
- sidpatil 5y agoFORTRAN, the OG of scientific languages, is not slow. In fact, that's why it's still used to this day.
- antoinealb 5y agoThat's true, i was more thinking of scientific interpreted languages, a la R, Mathematica, matlab
- dralley 5y agoIn fact it may well be the fastest language - although it's hard to compete with the sheer number of man hours spent on C/C++ compilers.
- adgjlsfhk1 5y agowhile it isn't inherently slow, all the open source compilers are missing a lot of modern improvements. The default libm in particular is often a few times slower than those provided by Julia.
- teleforce 5y agoIt is not the compiler per se, it is mostly down to the design of the language itself. D language based numerical library has already beaten popular Fortran based numerical library OpenBLAS/Lapack for several years now [1]. [1]Numeric age for D: Mir GLAS is faster than OpenBLAS and Eigen: http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/glas-gemm-benchmark.html http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...
- esjeon 5y agoMathematica is the worst when it comes to pure number crunching, because they use unstructured arrays. Much more flexible, but much slower.
- carry_bit 5y agoMathematica also has the more specialized packed and numeric array types.
- fault1 5y agonative python is indeed quite slow relative to anything compiled, especially when you want to use pure python for hot loops. it's really the saving grace of cython (or alternatives) that makes python tractible for a lot of scientific computing. 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.
- docfort 5y agoMATLAB has had a JIT at the function level for several years now that alleviates specifically that pain. But most guides still focus on vectorization for optimization.
- nick__m 5y agoLoops and other general purpose programming constructs are afterthoughts in Matlab! It's not really a general purpose language, it is at it's core a numerical computation language, it's made for matrices and vectors operations. If a Matlab user don't need Simulink or one of it's numerous costly toolboxes, this user should give Julia a try.
- esjeon 5y agoYeah, so I usually consider Mathematica as a fast prototyping tool. It offers some optimization tools(i.e. packed array, compile), but I find myself rewriting a significant portion of the program while trying to apply them. They work, but often not worth the effort. Still, it offers a very good set of features, and it's cleaner than some popular python libraries.
- nerdponx 5y agoIt might be a situation like the R language, where the language itself is too flexible to optimize well. 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.
- boublepop 5y agoIt’s not. Mathematica is extremely flexible yes, but it’s not hindering optimization. You can literally parallelize code and compile to c automatically.
- mateo1 5y agoI don't understand why this comment is so high up. It's just really naive to compare mathematica and python on runtime speed as if they're both tools used for the same purpose. Whether you like their choice of syntax or not, wolframs tools are state of the art on what they do. Just don't hammer your nails in with screwdrivers.
- notfromhere 5y agoWolfram had been trying to push its language as something that can replace python
- mkl 5y agoWolfram literally say Mathematica is intended to be for all computational purposes. From the article: "our vision is a grand one—unify all of computation into a single coherent language".
- MichaelRazum 5y agoWas my thought as well. Python is eating Mathematica and Matlab for lunch. I guess the reason is also, that FANG investend heavly in python. Even just by opensourcing tensorflow, pytorch, jax and so on.
- maccard 5y ago> I've had the displeasure of porting 4k sloc of Mathematica to python and the script runtime went from 40min to 5sec 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?
- carry_bit 5y agoI'd wonder if the Mathematica code was using fast constructs to begin with. 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.
- dataflow 5y ago"Python" as in "SymPy"? Was the translation actually equivalent? Did you try Compile[]? [1] [1] https://reference.wolfram.com/language/ref/Compile.html https://reference.wolfram.com/language/ref/Compile.html
- boublepop 5y agoSounds like the typical case of someone not understanding Mathematica. The 40min -> 5sec speed up can typically be achieved in Mathematica just by changing 1 to 1. The default is slower but always completely accurate, which is important for math, but less so for most numerical scripts. If that fails Mathematica can also just compile your script for you.
- mmarq 5y agoI'm not saying that's your case, but this reminds me of a colleague of mine who was tasked with building a piece of code to calculate some metric related to the adjacency of faulty parts in a production batch. 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.