[Date Index]
[Thread Index]
[Author Index]
Re: How I can I optimize the following code in order to get very
*To*: mathgroup at smc.vnet.net
*Subject*: [mg125108] Re: How I can I optimize the following code in order to get very
*From*: Szabolcs <szhorvat at gmail.com>
*Date*: Wed, 22 Feb 2012 05:28:43 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*References*: <jhvu3d$7vc$1@smc.vnet.net>
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
Prev by Date:
**Re: How best to implement a hash table in Mathematica**
Next by Date:
**Re: good list**
Previous by thread:
**Retrieving numerical value for ImagePadding**
Next by thread:
**Re: Kolmogorov Smirnov in two or more dimensions is in Mathematica 8.0.4**
| |