0

I often hear, in the physics community, that python is faster and overall better than mathematica for numeric calculations. But this seems very subjective since code badly written in one language can make it seem slow, compared to good code in another. So what evidences are there that this is true, or false?

codebpr
  • 2,233
  • 1
  • 7
  • 26
Felipe
  • 479
  • 8
  • 2
    Absolutely. Both Mathematica and Python are interpreted languages, so they both face the problem that loops and flow control constructs are very slow. You can expect good numerical performance only if you refactor your code so that it makes good use of compiled libraries. So what matters more than the actual scripting language is what libraries for linear algebra (BLAS, LAPACK, sparse matrix algebra) are linked. Performant code is still to be written in FORTRAN, C/C++ or CUDA, OpenCL, or whatever your GPU requires. – Henrik Schumacher Feb 08 '24 at 14:02
  • 2
    @HenrikSchumacher … maybe add Julia these days, if Fortran and C/C++ are listed? I find Julia a nice addition for people coming from WL (e.g., multiple dispatch, 1-indexing, meta programming). – gwr Feb 08 '24 at 14:25
  • Yeah, Julia is indeed interesting in this regard, because it exploits JIT compilation more than the other two to remedy some of the problems with interpreted languages. – Henrik Schumacher Feb 08 '24 at 14:31

0 Answers0