Xah Lee wrote:
> On Dec 1, 4:06 pm, Jon Harrop <[EMAIL PROTECTED]> 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.

Why?

> • 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://xahlee.org/MathematicaPrograming_dir/MathematicaTiming.nb

HTTP request sent, awaiting response... 403 Forbidden

>> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
>> http://www.ffconsultancy.com/?u
> 
> 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.
http://www.ffconsultancy.com/?u
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to