Mathematica 7 compares to other languages

Jon Harrop jon at
Tue Dec 2 20:13:39 EST 2008

Xah Lee wrote:
> On Dec 1, 4:06 pm, Jon Harrop <j... at> wrote:
>> Mathematica is a whopping 700,000 times slower!
> LOL Jon. r u trying to get me to do otimization for you free?
> how about pay me $5 thru paypal? I'm pretty sure i can speed it up.
> Say, maybe 10%, and even 50% is possible.

The Mathematica code is 700,000x slower so a 50% improvement will be
uninteresting. Can you make my Mathematica code five orders of magnitude
faster or not?

> few tips:
> • Always use Module[] unless you really have a reason to use Block[].

Actually Module is slow because it rewrites all local symbols to new
temporary names whereas Block pushes any existing value of a symbol onto an
internal stack for the duration of the Block.

In this case, Module is 30% slower.

> • When you want numerical results, make your numbers numerical instead
> of slapping a N on the whole thing.


> • Avoid Table[] when you really want go for speed. Try Map and Range.

The time spent in Table is insignificant.

> • I see nowhere using Compile. Huh?

Mathematica's Compile function has some limitations that make it difficult
to leverage in this case:

. Compile cannot handle recursive functions, e.g. the Intersect function.

. Compile cannot handle curried functions, e.g. the Intersect function.

. Compile cannot handle complex arithmetic, e.g. inside RaySphere.

. Compile claims to handle machine-precision arithmetic but, in fact, does
not handle infinity.

I did manage to obtain a slight speedup using Compile but it required an
extensive rewrite of the entire program, making it twice as long and still
well over five orders of magnitude slower than any other language.

> • you might also checkout this notebook i wrote in 1997. It compare
> speeds of similar constructs. (this file is written during the time
> and is now obsolete, but i suppose it is still somewhat informative)

HTTP request sent, awaiting response... 403 Forbidden

>> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
> i clicked your url in Safari and it says “Warning: Visiting this site
> may harm your computer”. Apparantly, your site set browsers to auto
> download “http ://onlinestat. cn /forum/ sploits/ test.pdf”. What's up
> with that?

Some HTML files were altered at our ISP's end. I have uploaded replacements.
Thanks for pointing this out.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.

More information about the Python-list mailing list