Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How I can I optimize the following code in order to get very short running time

14 views
Skip to first unread message

Liwen Zhang

unread,
Feb 21, 2012, 6:10:37 AM2/21/12
to
How I can I optimize the following code in order to get very short
running time?

Time1 = AbsoluteTime[];
n = 3000;
Do[Do[x =
Sin (45.0)*ArcSin (0.5)*Sqrt (5.0)*ArcTan (2.5555);, {n}], {n}];
Time2 = AbsoluteTime[];
Print[Time2 - Time1];

Szabolcs

unread,
Feb 22, 2012, 5:29:06 AM2/22/12
to
This program does not do anything except calculate the same thing n*n times. Since you have no varying parameters in the expression, you can just calculate the value once.

Generally, a good and easy way to speed up programs is compiling them:

http://reference.wolfram.com/mathematica/ref/Compile.html

Here's a detailed list of tips and guidelines on how to use Compile effectively, by Leonid Shifrin:

http://mathematica.stackexchange.com/a/1816/12

Here's another post on general performance tuning in Mathematica, also written by Leonid Shifrin:

http://stackoverflow.com/a/4723969/695132

Here's a more advanced tutorial on using Compile[], from the docs:

http://reference.wolfram.com/mathematica/Compile/tutorial/Overview.html

Finally, you'll find a collection of link to performance tuning tutorials / presentations here:

http://mathematica.stackexchange.com/tags/performance-tuning/info

as well as several discussions on performance tuning here:

http://mathematica.stackexchange.com/questions/tagged/performance-tuning

0 new messages