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


Groups > comp.soft-sys.math.mathematica > #8693

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

From Szabolcs <szhorvat@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How I can I optimize the following code in order to get very
Date 2012-02-22 10:29 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ji2g1i$k71$1@smc.vnet.net> (permalink)
References <jhvu3d$7vc$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web