Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8656 > unrolled thread

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

Started byLiwen Zhang <gearss8888@gmail.com>
First post2012-02-21 11:10 +0000
Last post2012-02-22 10:29 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How I can I optimize the following code in order to get very short running time Liwen Zhang <gearss8888@gmail.com> - 2012-02-21 11:10 +0000
    Re: How I can I optimize the following code in order to get very Szabolcs <szhorvat@gmail.com> - 2012-02-22 10:29 +0000

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

FromLiwen Zhang <gearss8888@gmail.com>
Date2012-02-21 11:10 +0000
SubjectHow I can I optimize the following code in order to get very short running time
Message-ID<jhvu3d$7vc$1@smc.vnet.net>
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];

[toc] | [next] | [standalone]


#8693 — Re: How I can I optimize the following code in order to get very

FromSzabolcs <szhorvat@gmail.com>
Date2012-02-22 10:29 +0000
SubjectRe: How I can I optimize the following code in order to get very
Message-ID<ji2g1i$k71$1@smc.vnet.net>
In reply to#8656
On Tuesday, 21 February 2012 13:10:37 UTC+2, Liwen Zhang  wrote:
> 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];

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web